Print

Print


Commit in slic on MAIN
include/CommandLineOption.hh+116added 1.1
       /CommandLineProcessor.hh+148added 1.1
       /CommandQueue.hh+71added 1.1
       /G4Application.hh+76-161.43 -> 1.44
       /CmdLineOpt.hh-1031.8 removed
       /CmdManager.hh-1281.13 removed
       /CmdRegistry.hh-691.10 removed
       /G4CmdQueue.hh-831.17 removed
src/CommandLineProcessor.cc+473added 1.1
   /CommandQueue.cc+46added 1.1
   /G4Application.cc+41-2191.74 -> 1.75
   /CmdManager.cc-2751.22 removed
   /CmdRegistry.cc-1591.14 removed
   /G4CmdQueue.cc-1281.17 removed
+971-1180
5 added + 7 removed + 2 modified, total 14 files
JM: First version of command line processing rewrite.

slic/include
CommandLineOption.hh added at 1.1
diff -N CommandLineOption.hh
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ CommandLineOption.hh	30 Nov 2006 02:32:23 -0000	1.1
@@ -0,0 +1,116 @@
+// $Header: /cvs/lcd/slic/include/CommandLineOption.hh,v 1.1 2006/11/30 02:32:23 jeremy Exp $
+
+#ifndef SLIC_COMMANDLINEOPTION_HH
+#define SLIC_COMMANDLINEOPTION_HH
+
+// stl
+#include <map>
+#include <vector>
+#include <string>
+
+namespace slic
+{
+
+  /**
+   * @author Jeremy McCormick <[log in to unmask]>
+   *
+   * @class  CommandLineOption
+   *
+   * @brief  Command-line option with a single letter, full name and description
+   *         plus an associated Geant4 command (which is optional).
+   *
+  */
+  class CommandLineOption
+  {
+
+  public:
+
+    /**
+     * The fully qualified constructor for CommandLineOption.
+     * (There are no setters for this class.)
+     */
+    CommandLineOption(const std::string& shortname,
+		      const std::string& longname,
+		      const std::string& description,
+		      unsigned int min_args=0,
+		      unsigned int max_args=0,
+		      const std::string& g4cmdstr="")
+      : m_shortname(shortname),
+	m_longname(longname),
+	m_description(description),
+	m_g4cmdstr(g4cmdstr),
+	m_minArgs(min_args),
+	m_maxArgs(max_args)
+    {;}
+
+    virtual ~CommandLineOption()
+    {;}
+
+  public:
+
+    /**
+     * Get the short name associated with this option.
+     * This must be a single letter, such as 'm'.
+     */
+    const std::string& getShortName() const
+    {
+      return m_shortname;
+    }
+
+    /**
+     * Get the long name associated with this option.
+     * This must be one or more words separated by dashes,
+     * such as "lcio-path".
+     */
+    const std::string& getLongName() const
+    {
+      return m_longname;
+    }
+
+    /**
+     * Get a brief description of this option.
+     */
+    const std::string& getDescription() const
+    {
+      return m_description;
+    }
+
+    /**
+     * Get the Geant4 command associated with this option.
+     * This may be a null string if there is no associated
+     * Geant4 command, though currently all of SLIC's options
+     * have a corresponding Geant4 macro command.
+     */
+    const std::string& getG4CommandString() const
+    {
+      return m_g4cmdstr;
+    }
+
+    /**
+     * Get the minimum number of arguments to this option.    
+     */
+    unsigned int getMinArgs() const
+    {
+      return m_minArgs;
+    }
+
+    /**
+     * Get the maximum number of arguments to this option.
+     */
+    unsigned int getMaxArgs() const
+    {
+      return m_maxArgs;
+    }
+
+  private:
+
+    std::string m_shortname;
+    std::string m_longname;
+    std::string m_description;
+    std::string m_g4cmdstr;
+    int m_minArgs;
+    int m_maxArgs;
+  };
+}
+
+#endif

slic/include
CommandLineProcessor.hh added at 1.1
diff -N CommandLineProcessor.hh
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ CommandLineProcessor.hh	30 Nov 2006 02:32:23 -0000	1.1
@@ -0,0 +1,148 @@
+// $id: $
+#ifndef SLIC_COMMANDLINEPROCESSOR_HH
+#define SLIC_COMMANDLINEPROCESSOR_HH
+
+// stl
+#include <iostream>
+#include <string>
+#include <map>
+#include <vector>
+
+// slic
+#include "CommandLineOption.hh"
+#include "CommandQueue.hh"
+#include "Module.hh"
+#include "Singleton.hh"
+
+namespace slic
+{ 
+  /**
+   * @author Jeremy McCormick 
+   *
+   * @brief  Command line processor for SLIC using getopt.
+   *
+   * @note All options are mapped in a straightforward fashion
+   *       to Geant4 macro commands that may be defined 
+   *       within LCDD, SLIC, or Geant4 itself.  The result
+   *       of processing the command line using this class is
+   *       to fill the CommandQueue, which is then retrieved 
+   *       and executed by G4Application.
+   */
+  class CommandLineProcessor : public Module, public Singleton<CommandLineProcessor>
+  {
+
+  public:
+
+    typedef std::pair<std::string, std::string> OptionsPair;
+    typedef std::vector<CommandLineProcessor::OptionsPair> CommandLineArguments;
+    typedef std::vector<CommandLineOption*> OptionsList;
+
+  public:
+    virtual ~CommandLineProcessor();
+    CommandLineProcessor();
+
+  public:
+
+    /**
+     * This is the primary function to process the raw arguments.
+     * Options that will cause an abort, e.g. '-h', '-v', and '-n',
+     * are handled explicitly so that the correct flag is set.
+     * Other arguments are handled generically and put into the 
+     * CommandLineArguments vector, which associates a short
+     * option name with its arguments (if any).  Options that can 
+     * occur more than once, such as the '-m' command, get one entry 
+     * per occurrence in the CommandLineArguments.  getopt will
+     * check that the option is valid valid and that enough arguments
+     * were received before the command is put into CommandLineArguments.  
+     * After calling this function, the function getCommandQueue() will 
+     * return the list of Geant4 macro commands that resulted from 
+     * processing the raw command line arguments.
+     */
+    void process(int argc, char** argv);
+
+    /**
+     * Print the usage statement.
+     */
+    void printUsage(std::ostream& os) const;
+
+    /**
+     * Print the version information.
+     */
+    void printVersion(std::ostream& os) const;
+
+    /**
+     * Register the list of valid command line options.
+     */
+    void registerOptions();
+
+    /**
+     * Abort the application before Geant4 starts, 
+     * e.g. if usage or version are selected.
+     * This is not called if the command line arguments
+     * are invalid, as getopt will handle this and
+     * call exit() itself.
+     */
+    void abort();
+
+    /**
+     * Process a command line switch by adding
+     * the corresponding Geant4 macro command to
+     * the CommandQueue.
+     */
+    void processOption(const std::string&);
+
+    /**
+     * Add a command line option describing a
+     * command line switch, its full name,
+     * description, geant4 command, etc. 
+     */
+    void addOption(CommandLineOption*);
+  
+    /**
+     * Get the queue of Geant4 macro commands created from
+     * the command line arguments.
+     */
+    CommandQueue* getCommandQueue();
+
+    /**
+     * Find an option specification by its single letter designation (with no '-').
+     */
+    CommandLineOption* getCommandLineOption(const std::string& opt);
+
+    /**
+     * Returns true if the option was found in the command line arguments.
+     */
+    bool haveOption(const std::string& opt);
+
+    /**
+     * Print out the options table.
+     */
+    void printOptions(std::ostream&) const;
+
+  private:
+
+    /**
+     * Process all the command line arguments in correct
+     * order to create the queue of Geant4 commands.
+     */
+    void processOptions();
+
+  private:
+    
+    // A vector of options with their arguments.
+    CommandLineArguments m_commandline;
+
+    // A list Geant4 macro commands filled by processing the command line arguments.
+    CommandQueue m_g4q;
+
+    // The list of valid options and their associated meta-data.
+    OptionsList m_cmds;
+
+    // Flags to be set by the process function.
+    int m_help_flag;
+    int m_interactive_flag;
+    int m_version_flag;
+  };
+}
+
+#endif

slic/include
CommandQueue.hh added at 1.1
diff -N CommandQueue.hh
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ CommandQueue.hh	30 Nov 2006 02:32:23 -0000	1.1
@@ -0,0 +1,71 @@
+// $Header: /cvs/lcd/slic/include/CommandQueue.hh,v 1.1 2006/11/30 02:32:23 jeremy Exp $
+
+#ifndef SLIC_COMMANDQUEUE_HH
+#define SLIC_COMMANDQUEUE_HH
+
+// std
+#include <iostream>
+#include <vector>
+#include <string>
+
+namespace slic
+{
+  /**
+   * @class CommandQueue
+   * @brief A queue of G4 commands to be executed in order.
+   * @note  Created by CommandLineProcessor from the command line arguments.
+   */
+  class CommandQueue
+  {
+  public:
+
+    typedef std::vector<std::string> CmdVecType;
+    typedef std::string CmdType;
+    typedef size_t SizeType;
+
+  public:
+
+    CommandQueue()
+    {}
+
+    virtual ~CommandQueue()
+    {}
+
+    void add(const CmdType& g4cmd)
+    {
+      m_commands.push_back( g4cmd );
+    }
+
+    void add(const char* g4cmd)
+    {
+      std::string cmdStr = g4cmd;
+      add(std::string(cmdStr));
+    }
+
+    CmdVecType::iterator cmdsBegin()
+    {
+      return m_commands.begin();
+    }
+
+    CmdVecType::iterator cmdsEnd()
+    {
+      return m_commands.end();
+    }
+
+    void printOut(std::ostream& os);
+    
+    void execute();
+
+    void clear()
+    {
+      m_commands.clear();
+    }
+
+    CmdVecType::iterator find(const std::string& str);
+
+  private:
+    CmdVecType m_commands;
+  };
+}
+
+#endif

slic/include
G4Application.hh 1.43 -> 1.44
diff -u -r1.43 -r1.44
--- G4Application.hh	5 Sep 2006 23:21:42 -0000	1.43
+++ G4Application.hh	30 Nov 2006 02:32:24 -0000	1.44
@@ -1,4 +1,4 @@
-// $Header: /cvs/lcd/slic/include/G4Application.hh,v 1.43 2006/09/05 23:21:42 jeremy Exp $
+// $Header: /cvs/lcd/slic/include/G4Application.hh,v 1.44 2006/11/30 02:32:24 jeremy Exp $
 
 #ifndef SLIC_G4APPLICATION_HH
 #define SLIC_G4APPLICATION_HH 1
@@ -35,77 +35,137 @@
    * @class G4Application
    * @brief Singleton class for a Geant4 application.
    * @note  Instantiates manager and messenger classes, including
-   *        user actions, G4RunManager, CmdManager, GeneratorManager
-   *        and PhysicsListManager.
+   *        user actions, G4RunManager, GeneratorManager, and PhysicsListManager.
    */
   class G4Application : public Singleton<G4Application>
   {
 
   public:
 
-    /* Indicates batch or interactive mode */
+    /** 
+     * Indicates the run mode: batch or interactive. 
+     */
     enum ERunMode { eBatch=1, eInteractive=2 };
 
   public:
 
-    ~G4Application();
-
-    //G4Application(int, char**);
+    /**
+     * The constructor.
+     */
     G4Application();
 
+    /**
+     * The destructor.
+     */
+    virtual ~G4Application();
+
   public:
 
-    // Return SLIC's RunManager instance.
+    /** 
+     * Return SLIC's RunManager instance.
+     */
     RunManager* getRunManager();
 
-    // Initialize the application.
+    /** 
+     * Initialize the application.
+     */
     void initialize();
 
-    // Run the application.
+    /**
+     * Run the application.
+     */
     void run();
 
+    /**
+     * Print the usage by calling the CommandLineProcessor.
+     */
     void printUsage(std::ostream& os);
 
+    /**
+     * Print the version string.
+     */
     void printVersion(std::ostream& os);
 
+    /** 
+     * Print SLIC's splash screen. 
+     */
     void printSplashScreen(std::ostream& os) const;
 
-    // print startup time
+    /** 
+     * Print the start time.
+     */
     static void printStartTime(std::ostream& os);
 
-    // print end time
+    /** 
+     * Print the end time.
+     */
     static void printEndTime(std::ostream& os);
 
+    /** 
+     * Get the return code.
+     */
     int getReturnCode() const;
 
+    /** 
+     * Get the run mode, interactive or batch.
+     */
     ERunMode getMode() const;
 
+    /** 
+     * Set abort state.
+     */
     void setAborting(bool a = true);
 
+    /** 
+     * Check abort state.
+     */
     bool isAborting() const;
 
+    /** 
+     * Set the run mode.
+     */
     void setMode(ERunMode rmode);
 
+    /** 
+     * Get the name of the binary as it was invoked.
+     */
     const std::string& getBinaryName() const;
 
+    /** 
+     * Get the base name of the binary (file name only).
+     */
     const std::string& getBinaryBasename() const;
 
+    /** 
+     * Setup SLIC from command line arguments using the CommandLineProcessor.
+     */
     void setupFromCommandLine(int, char**);
 
+    /** 
+     * Set the return code.
+     */
     void setReturnCode(int rc);
 
-  protected:
-
-    void registerCmdLineOpts();
-
   private:
 
+    /** 
+     * Set the binary base name from the full name.
+     */
     void setBinaryBasename();
 
+    /** 
+     * Register the Geant4 user action classes with the G4RunManager.
+     */
     void setupUserActions();
 
+    /** 
+     * Initialize the Geant4 user interface.
+     */
     void initializeUI();
 
+    /**
+     * Initialize the Geant4 visualization subsystem.
+     */
 #ifdef G4VIS_USE
     void initializeVis();
 #endif

slic/include
CmdLineOpt.hh removed after 1.8
diff -N CmdLineOpt.hh
--- CmdLineOpt.hh	5 Sep 2006 23:21:41 -0000	1.8
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,103 +0,0 @@
-// $Header: /cvs/lcd/slic/include/Attic/CmdLineOpt.hh,v 1.8 2006/09/05 23:21:41 jeremy Exp $
-
-#ifndef SLIC_CMDLINEOPT_HH
-#define SLIC_CMDLINEOPT_HH
-
-// std
-#include <map>
-#include <vector>
-#include <string>
-
-namespace slic
-{
-
-  /**
-   * @class CmdLineOpt
-   * @brief Command-line option with a single letter, full name and description.
-   * @todo  Actually use the min and max args.
-  */
-  class CmdLineOpt
-  {
-
-  public:
-    enum ENumArgs { eNoArgs = 0, eUnlimited = -1 };
-
-  public:
-    CmdLineOpt()
-    {
-      setArgRange(0, 0);
-    }
-
-    CmdLineOpt(const std::string& cl_opt,
-	       const std::string& cl_name,
-	       const std::string& description,
-	       int min_args = 0,
-	       int max_args = 0)
-      : m_opt(cl_opt),
-	m_name(cl_name),
-	m_description(description),
-	m_minArgs(min_args),
-	m_maxArgs(max_args)
-    {;}
-
-    virtual ~CmdLineOpt()
-    {;}
-
-    void setOpt(const std::string& s)
-    {
-      m_opt = s;
-    }
-
-    void setName(const std::string& s)
-    {
-      m_name = s;
-    }
-
-    void setDescription(const std::string& s)
-    {
-      m_description = s;
-    }
-
-    void setArgRange(int min = 0, int max = 0)
-    {
-      m_minArgs = 0;
-      m_maxArgs = 0;
-    }
-
-    const std::string& getOpt() const
-    {
-      return m_opt;
-    }
-
-    const std::string& getName() const
-    {
-      return m_name;
-    }
-
-    const std::string& getDescription() const
-    {
-      return m_description;
-    }
-
-    int getMinArgs() const
-    {
-      return m_minArgs;
-    }
-
-    int getMaxArgs() const
-    {
-      return m_maxArgs;
-    }
-
-  private:
-
-    std::string m_opt;
-    std::string m_name;
-    std::string m_description;
-
-    int m_minArgs;
-    int m_maxArgs;
-  };
-}
-
-#endif

slic/include
CmdManager.hh removed after 1.13
diff -N CmdManager.hh
--- CmdManager.hh	14 Nov 2006 10:27:03 -0000	1.13
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,128 +0,0 @@
-// $Header: /cvs/lcd/slic/include/Attic/CmdManager.hh,v 1.13 2006/11/14 10:27:03 jeremy Exp $
-
-#ifndef SLIC_CMDMANAGER_HH
-#define SLIC_CMDMANAGER_HH 1
-
-// slic
-#include "Module.hh"
-#include "CmdRegistry.hh"
-#include "CmdArgs.hh"
-#include "G4CmdQueue.hh"
-#include "Singleton.hh"
-
-namespace slic
-{
-
-  /**
-     @class CmdManager
-     @brief Singleton manager for command-line input.
-  */
-  class CmdManager : public Module, public Singleton<CmdManager>
-  {
-
-  public:
-    virtual ~CmdManager();
-
-    CmdManager();
-
-  public:
-
-    /**
-     * Adds the command line option and associates
-     * it with the given Geant4 command string.
-     */
-    void addCmd(CmdLineOpt* cl, std::string s);
-
-    /** 
-     * Makes a queue of Geant4 macro commands to 
-     * execute from the input arguments.  If
-     * the command queue is empty, the usage
-     * command will be added automatically.
-     */
-    void fillG4CmdQueue();
-    
-    /**
-     * Setup the CmdManager from the command line
-     * options.
-     */
-    void fillCmdArgs(int argc, char** argv);
-
-    /**
-     * Checks whether a string looks like
-     * a command line switch, like "-x".
-     */
-    bool isCmdOpt(const std::string& token);
-
-    /**
-     * Checks whether a string looks like
-     * the full command line option, like "--cmd".
-     */
-    bool isCmdName(const std::string& token);
-
-    /**
-     * Get the arguments that were passed from command line. 
-     */
-    CmdArgs* getCmdArgs();
-
-    /**
-     * Get the registry of valid command line arguments     
-     */
-    CmdRegistry* getCmdRegistry();
-
-    /**
-     * Get the queue of Geant4 commands generated from command line arguments.
-     */
-    G4CmdQueue* getG4CmdQueue();
-
-    /**
-     * Execute and then clear the current Geant4
-     * command queue.
-     */
-    void execCurrG4CmdQueue(bool clear_it = true);
-
-    /**
-     * Clear the current Geant4 command queue. 
-     */
-    void clearG4CmdQueue();
-
-    /**
-     * Checks if usage should be printed.
-     */
-    bool isPrintUsage() const;
-
-    /**
-     * Checks if the version should be printed.
-     */
-    bool isPrintVersion() const;
-
-    /**
-     * Changes state to clear the current
-     * queue and add the command to print
-     * a version string.   
-     */
-    inline void setPrintVersion(bool b=true);
-    
-    /**
-     * Changes state to clear the current
-     * queue and add the command to print
-     * the usage menu.
-     */
-    inline void setPrintUsage(bool b=true);
-
-  private:
-
-    // valid command line options registry
-    CmdRegistry m_cmdRegistry;
-
-    // CL args converted to str tokens
-    CmdArgs m_args;
-
-    // strings of G4 commands to be executed
-    G4CmdQueue m_cmdQueue;
-
-    bool m_printUsage;
-    bool m_printVersion;
-  };
-}
-
-#endif

slic/include
CmdRegistry.hh removed after 1.10
diff -N CmdRegistry.hh
--- CmdRegistry.hh	5 Sep 2006 23:21:41 -0000	1.10
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,69 +0,0 @@
-// $Header: /cvs/lcd/slic/include/Attic/CmdRegistry.hh,v 1.10 2006/09/05 23:21:41 jeremy Exp $
-
-#ifndef SLIC_CMDREGISTRY_HH
-#define SLIC_CMDREGISTRY_HH 1
-
-// slic
-#include "CmdLineOpt.hh"
-
-// std
-#include <iostream>
-
-namespace slic
-{
-
-  /**
-     @class CmdRegistry
-     @brief Maps a CmdLineOpt to a single G4 command.
-     @note  CmdRegistry owns its registered CmdLineOpt pntrs and will delete them in its dtor.
-  */
-  class CmdRegistry
-  {
-  public:
-
-    // opts to a single G4 cmd
-    typedef std::pair<CmdLineOpt*, std::string> CmdOptToG4CmdPair;
-
-    // vec of above pairing
-    typedef std::vector<CmdOptToG4CmdPair> CmdRegType;
-
-  public:
-
-    CmdRegistry()
-    {}
-
-    virtual ~CmdRegistry()
-    {
-      deleteCmdLineOpts();
-    }
-
-  public:
-
-    void deleteCmdLineOpts();
-
-    // insert cmd by copy
-    void addCmd(CmdLineOpt* cl, std::string s);
-
-    const std::string& getIsInStr();
-
-    // find by opt
-    std::string findG4CmdStrByOpt(const std::string& opt);
-
-    // find by name
-    std::string findG4CmdStrByName(const std::string& name);
-
-    CmdLineOpt* findCmdLineOptByName(const std::string& name);
-
-    CmdLineOpt* findCmdLineOptByOpt(const std::string& opt);
-
-    void printOut(std::ostream &os) const;
-
-  private:
-
-    CmdRegType m_cmds;
-
-    std::string m_isInStr;
-  };
-}
-
-#endif

slic/include
G4CmdQueue.hh removed after 1.17
diff -N G4CmdQueue.hh
--- G4CmdQueue.hh	5 Sep 2006 23:21:43 -0000	1.17
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,83 +0,0 @@
-// $Header: /cvs/lcd/slic/include/Attic/G4CmdQueue.hh,v 1.17 2006/09/05 23:21:43 jeremy Exp $
-
-#ifndef SLIC_G4CMDQUEUE_HH
-#define SLIC_G4CMDQUEUE_HH
-
-// std
-#include <iostream>
-#include <vector>
-#include <string>
-
-namespace slic
-{
-
-  /**
-     @class G4CmdQueue
-     @brief A queue of G4 commands to be executed.
-     @note  Filled by CmdManager from CL args.
-  */
-  class G4CmdQueue
-  {
-  public:
-
-    typedef std::vector<std::string> CmdVecType;
-    typedef std::string CmdType;
-    typedef size_t SizeType;
-
-  public:
-
-    G4CmdQueue()
-    {}
-
-    virtual ~G4CmdQueue()
-    {}
-
-    void addCmd(const CmdType& g4cmd)
-    {
-      m_commands.push_back( g4cmd );
-    }
-
-    void addCmd(const char* g4cmd)
-    {
-      std::string cmdStr = g4cmd;
-      addCmd(std::string(cmdStr));
-    }
-
-    CmdVecType::iterator cmdsBegin()
-    {
-      return m_commands.begin();
-    }
-
-    CmdVecType::iterator cmdsEnd()
-    {
-      return m_commands.end();
-    }
-
-    void printOut(std::ostream& os);
-
-    void execCmds();
-
-    void clear()
-    {
-      m_commands.clear();
-    }
-
-    void prepare();
-
-    CmdVecType::iterator find_cmd(const std::string& str);
-
-  private:
-
-    void reorder();
-    void setInitialize();
-    void reorderBeamOn();
-    void reorder_dumpGDML();
-    CmdVecType::iterator find_init();
-
-  private:
-
-    CmdVecType m_commands;
-  };
-}
-
-#endif

slic/src
CommandLineProcessor.cc added at 1.1
diff -N CommandLineProcessor.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ CommandLineProcessor.cc	30 Nov 2006 02:32:27 -0000	1.1
@@ -0,0 +1,473 @@
+// $Id: CommandLineProcessor.cc,v 1.1 2006/11/30 02:32:27 jeremy Exp $
+
+#include "CommandLineProcessor.hh"
+
+// slic
+#include "PackageInfo.hh"
+#include "CommandQueue.hh"
+#include "CommandLineOption.hh"
+
+// getopt
+#include "getopt.h"
+
+// stl
+#include <sstream>
+
+using namespace std;
+
+namespace slic
+{  
+  CommandLineProcessor::CommandLineProcessor()
+    : Module("CommandLineProcessor"),
+      m_help_flag(0),
+      m_interactive_flag(0),
+      m_version_flag(0)
+  {
+    registerOptions();
+  }
+
+  CommandLineProcessor::~CommandLineProcessor()
+  {}
+
+  void CommandLineProcessor::process(int argc, char** argv)
+  {    
+    // Description of SLIC's options in getopt's format.
+    static struct option long_options[] = {
+      {"help", no_argument, 0, 'h'},
+      {"help", no_argument, 0, '?'},                
+      {"version", no_argument, 0, 'v'},
+      {"interactive", no_argument, 0, 'n'},
+      {"macro", required_argument, 0, 'm'},
+      {"event-file", required_argument, 0, 'i'},
+      {"lcdd-url", required_argument, 0, 'g'},
+      {"lcio-file", required_argument, 0, 'o'},
+      {"lcio-path", required_argument, 0, 'p'},
+      {"autoname", optional_argument, 0, 'O'},
+      {"lcio-delete", no_argument, 0, 'x'},
+      {"run-events", required_argument, 0, 'r'},
+      {"skip-events", required_argument, 0, 's'},
+      {"physics-list", required_argument, 0, 'l'},
+      {"log-file", required_argument, 0, 'L'},
+      {"seed", required_argument, 0, 'd'},
+      {"dump-gdml", optional_argument, 0, 'G'},    
+      {0, 0, 0, 0}
+    };
+     
+    while (1) {
+            
+      int option_index = 0;
+      int c;
+     
+      // Call getopt to set the next option.
+      c = getopt_long (argc, argv, "h?nvm:g:i:o:p:Oxr:s:l:L:d:G",
+		       long_options, &option_index);
+
+      // Done.
+      if ( c == -1 ) 
+	break;
+      
+      // Handle options.
+      switch (c) {
+
+      case 'h':	
+	m_help_flag=1;
+	break;
+
+      case '?':
+	m_help_flag=1;
+	break;
+
+      case 'n':
+	m_interactive_flag=1;
+	break;
+
+      case 'v':
+	m_version_flag=1;
+	break;		
+
+      default:     
+
+	stringstream ostr;
+	char cc = (char)c;
+	ostr << cc;
+	string theopt = ostr.str();
+
+	if ( optarg ) {
+	  m_commandline.push_back(OptionsPair(theopt, optarg));
+	}
+	else {
+	  m_commandline.push_back(OptionsPair(theopt, ""));
+	}
+	
+	break;
+      }
+    }
+
+    // Version takes first precedence.
+    // Print the version information and abort.
+    if (m_version_flag) {
+      printVersion(std::cout);
+      abort();
+    }    
+    // Help/usage is second precedence.
+    // Print the usage and abort if the help flag was
+    // passed or if there were no commandline arguments.
+    else if (m_help_flag || m_commandline.size() == 0 ) {
+      printUsage(std::cout);
+      abort();
+    }
+    // Default is process all the options and build the CommandQueue.
+    else {  
+      processOptions();
+    }
+  }
+
+  void CommandLineProcessor::printUsage(std::ostream& os) const
+  {
+    printVersion(os);
+
+    os << std::endl;
+    os << "**************" << std::endl;
+    os << "* SLIC Usage *" << std::endl;
+    os << "**************" << std::endl;
+
+    os << std::endl;
+    os << "Command line usage: " << std::endl;
+    os << std::endl;
+    os << "slic [single_macro_path]" << std::endl;
+    os << "slic [options]" << std::endl;
+
+    os << std::endl;
+
+    os << "Interactive usage: " << std::endl;
+    os << std::endl;
+    os << "slic -n" << std::endl;
+
+    os << std::endl;
+
+    printOptions( os );
+
+    os << std::endl;
+  }
+
+  void CommandLineProcessor::printVersion(std::ostream& os) const
+  {
+    os << PackageInfo::getFullApplicationString() << std::endl;
+  }
+
+  void CommandLineProcessor::abort()
+  {
+    exit(0);
+  }
+
+  void CommandLineProcessor::registerOptions()
+  {
+    // Print application usage. 
+    addOption(new CommandLineOption("h",
+			     "help",
+			     "Print SLIC usage.",
+			     0,
+			     0,
+			     "/slic/usage"));
+    
+    // Run in interactive mode.
+    addOption(new CommandLineOption("n",
+			     "interactive",
+			     "Start a Geant4 interactive session.",
+			     0,
+			     0,
+			     "/control/interactive"));
+
+    // Print SLIC version info.
+    addOption(new CommandLineOption("v",
+			     "version",
+			     "Print SLIC version.",
+			     0,
+			     0,
+			     "/slic/version"));
+
+    // Execute the commands from a macro file.
+    addOption(new CommandLineOption("m",
+			     "macro",
+			     "Execute Geant4 commands from a file.",
+			     1,
+			     1,
+			     "/control/execute"));
+    
+    // Set the URL of the input LCDD file. 
+    addOption(new CommandLineOption("g",
+			     "lcdd-url",
+			     "Set LCDD geometry file URL.",
+			     1,
+			     1,
+			     "/lcdd/url"));
+
+    // Set the path to a generator file, e.g. StdHep or LCIO.
+    addOption(new CommandLineOption("i",
+			     "event-file",
+			     "Set event input file full path.",
+			     1,
+			     1, 
+			     "/generator/filename"));
+
+    // Set the name of the LCIO output file. 
+    addOption(new CommandLineOption("o",
+			     "lcio-file",
+			     "Set name of LCIO output file.",
+			     1,
+			     1,
+			     "/lcio/filename"));
+
+    // Set the path of output files. 
+    addOption(new CommandLineOption("p",
+			     "lcio-path",
+			     "Set directory for LCIO output.",
+			     1,
+			     1,
+			     "/lcio/path"));
+    
+    // Automatically name the LCIO output file.
+    addOption(new CommandLineOption("O",
+			     "autoname",
+			     "Automatically name the LCIO output file.",
+			     0,
+			     1,
+			     "/lcio/autoname"));
+
+    // Overwrite an existing LCIO output file.
+    addOption(new CommandLineOption("x",
+			     "lcio-delete",
+			     "Delete an existing LCIO file.",
+			     0,
+			     0,
+			     "/lcio/fileExists delete"));
+
+    // Number of events to run.
+    addOption(new CommandLineOption("r",
+			     "run-events",
+			     "Run # of events.",
+			     1,
+			     1,
+			     "/run/beamOn"));
+
+    // Set number of events to skip from a file-based event source (e.g. StdHep).
+    addOption(new CommandLineOption("s",
+			     "skip-events",
+			     "Set number of events to skip.",
+			     1,
+			     1,
+			     "/generator/skipEvents"));
+
+    // Set the physics list. 
+    addOption(new CommandLineOption("l",
+			     "physics-list",
+			     "Set Geant4 physics list.",
+			     1,
+			     1,
+			     "/physics/select"));
+
+    // Set the name of the log file. 
+    addOption(new CommandLineOption("L",
+			     "log-file",
+			     "Set logfile name.",
+			     0,
+			     0,
+			     "/log/filename"));
+    
+    // Set the random seed.
+    addOption(new CommandLineOption("d",
+			     "seed",
+			     "Set the random seed.  (No argument seeds with time.)",
+			     0,
+			     1,
+			     "/random/seed"));
+
+    // Dump the loaded Geant4 geometry to a GDML file.
+    addOption(new CommandLineOption("G",
+			     "dump-gdml",
+			     "Dump geometry to GDML file.",
+			     0,
+			     1,
+			     "/lcdd/dumpGDML"));
+  }
+
+  void CommandLineProcessor::processOption(const string& opt) 
+  {      
+    // Loop over all input arguments to look for this option.
+    for ( CommandLineArguments::iterator it = m_commandline.begin();
+	  it != m_commandline.end();
+	  it++ ) {
+
+      // Look for a matching switch in the arguments.
+      if ( it->first == opt ) {
+       
+	// Get the associated specification for this option.
+	CommandLineOption* cmdlineopt = getCommandLineOption(opt);
+
+	// We must have a valid option!
+	assert(cmdlineopt != 0);
+
+	// Get the associated Geant4 command string.
+	string cmdstr = cmdlineopt->getG4CommandString();
+
+	// Add arguments to the command string, if some were passed.
+	if ( it->second != "" ) {
+	  cmdstr += " ";
+	  cmdstr += it->second;
+	}
+
+	// Add the command string to the CommandQueue.
+	m_g4q.add(cmdstr);
+      }
+    }
+  }
+
+  void CommandLineProcessor::addOption(CommandLineOption* opt)
+  {
+    m_cmds.push_back(opt);
+  }   
+
+  void CommandLineProcessor::processOptions()
+  {
+    // Logger.
+    processOption("L");
+
+    // Geometry file.
+    processOption("g");
+
+    // Physics list.
+    processOption("l");
+    
+    // Add initialization after geometry and physics,
+    // but only if there was a geometry file argument.
+    // Otherwise, initialize is not called, and the
+    // user is given the PreInit prompt.
+    if ( haveOption("g") ) {
+      m_g4q.add("/run/initialize");
+    }
+    
+    // Dump gdml.
+    processOption("G");
+
+    // Random seed.
+    processOption("d");
+
+    // Event file.
+    processOption("i");
+
+    // Output path.
+    processOption("p");
+
+    // Delete existing LCIO file.
+    processOption("x");
+
+    // Set LCIO file name.
+    processOption("o");
+
+    // Autoname the LCIO file.
+    processOption("O");
+
+    // Geant4 macro to run.
+    processOption("m");
+
+    // Events to skip.
+    processOption("s");
+
+    // Events to run.
+    processOption("r");
+    
+    // Interactive mode, if selected.
+    if (m_interactive_flag) {
+      m_g4q.add("/control/interactive");
+    }    
+  }
+
+  CommandQueue* CommandLineProcessor::getCommandQueue()
+  {
+    return &m_g4q;
+  }
+
+  void CommandLineProcessor::printOptions(std::ostream &os) const
+  {
+    os << "************************" << std::endl;
+    os << "* Command Line Options *" << std::endl;
+    os << "************************" << std::endl;
+    os << std::endl;
+
+    static const int opt_width = 8;
+    static const int descr_width = 15;
+    static const int name_width = 16;
+    static const int cmd_width = 24;
+    static const int sep_width = 60;
+
+    os.width(opt_width);
+    os << left << "Option";
+
+    os.width(name_width);
+    os << left << "Full Name";
+
+    os.width(cmd_width);
+    os << left << "Macro Command";
+
+    os.width(descr_width);
+    os << left << "Description";
+
+    os.fill('-');
+    os.width(sep_width);
+
+    os << std::endl;
+    os << '-' << std::endl;
+
+    os.fill(' ');
+
+    for ( OptionsList::const_iterator iter = m_cmds.begin();
+	  iter != m_cmds.end();
+	  iter++ ) {
+      CommandLineOption* cl_opt = (*iter);
+
+      std::string opt_str = "-" + cl_opt->getShortName();
+      os.width(opt_width);
+      os << left << opt_str;
+
+      std::string name_str = "--" + cl_opt->getLongName();
+      os.width(name_width);
+      os << left << name_str;
+
+      os.width(cmd_width);
+      os << left << cl_opt->getG4CommandString();
+
+      os.width(descr_width);
+      os << left << cl_opt->getDescription();
+
+      os << std::endl;
+    }
+  }
+
+  CommandLineOption* CommandLineProcessor::getCommandLineOption(const std::string& opt)
+  {
+    CommandLineOption* clo = 0;
+    for ( OptionsList::const_iterator iter = m_cmds.begin();
+	  iter != m_cmds.end();
+	  iter++ ) {
+      if ( (*iter)->getShortName() == opt ) {
+	clo = (*iter);
+	break;
+      }
+    }
+    return clo;
+  }
+
+  bool CommandLineProcessor::haveOption(const std::string& opt)
+  {
+    bool haveoption = false;
+    for ( CommandLineArguments::iterator it = m_commandline.begin();
+	  it != m_commandline.end();
+	  it++ ) {
+      if ( (*it).first == opt ) {
+	haveoption=true;
+	break;
+      }
+    }
+    return haveoption;
+  }
+} // namespace slic

slic/src
CommandQueue.cc added at 1.1
diff -N CommandQueue.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ CommandQueue.cc	30 Nov 2006 02:32:27 -0000	1.1
@@ -0,0 +1,46 @@
+// $Header: /cvs/lcd/slic/src/CommandQueue.cc,v 1.1 2006/11/30 02:32:27 jeremy Exp $
+
+#include "CommandQueue.hh"
+
+// geant4
+#include "G4UImanager.hh"
+
+namespace slic
+{
+  void CommandQueue::printOut(std::ostream& os) 
+  {
+    std::cout << std::endl;
+    os << "********************" << std::endl;
+    os << "* G4 Command Queue *" << std::endl;
+    os << "********************" << std::endl;
+    for ( CmdVecType::iterator iter = cmdsBegin();
+	  iter != cmdsEnd();
+	  iter++ ) {
+      os << *iter << std::endl;
+    }
+    std::cout << std::endl;
+  }
+
+  void CommandQueue::execute()
+  {
+    for ( CmdVecType::iterator iter = cmdsBegin();
+	  iter != cmdsEnd();
+	  iter++ ) {
+      std::string cmd = *iter;
+      G4UImanager::GetUIpointer()->ApplyCommand( cmd );
+    }    
+  }
+
+  CommandQueue::CmdVecType::iterator CommandQueue::find(const std::string& str)
+  {
+    CmdVecType::iterator iter = m_commands.begin();
+    for ( ;
+	  iter != m_commands.end();
+	  iter++ ) {
+      if ( (*iter).find(str) != std::string::npos ) {
+	break;
+      }
+    }
+    return iter;
+  }
+}

slic/src
G4Application.cc 1.74 -> 1.75
diff -u -r1.74 -r1.75
--- G4Application.cc	14 Nov 2006 10:27:04 -0000	1.74
+++ G4Application.cc	30 Nov 2006 02:32:27 -0000	1.75
@@ -1,8 +1,10 @@
-// $Header: /cvs/lcd/slic/src/G4Application.cc,v 1.74 2006/11/14 10:27:04 jeremy Exp $
+// $Header: /cvs/lcd/slic/src/G4Application.cc,v 1.75 2006/11/30 02:32:27 jeremy Exp $
+
 #include "G4Application.hh"
 
 // slic
-#include "CmdManager.hh"
+#include "CommandLineProcessor.hh"
+#include "CommandQueue.hh"
 #include "EventAction.hh"
 #include "EventDebugger.hh"
 #include "EventSourceManager.hh"
@@ -44,7 +46,7 @@
 #endif
 #endif // G4UI_NONE
 
-// std
+// stl
 #include <stdexcept>
 
 using std::cerr;
@@ -65,10 +67,7 @@
       m_returnCode(0),
       m_setRunAbort(false),
       m_isInitialized(false)
-  {
-    // Register the map of command line options to Geant4 commands.
-    registerCmdLineOpts();
-  }
+  {;}
 
   G4Application::~G4Application()
   {
@@ -93,22 +92,13 @@
 
   void G4Application::setupFromCommandLine(int argc, char** argv)
   {
-    /*
-     * Set the name and basename of slic's binary from the command line arguments.
-     */
+    // Set the name and basename of slic's binary from the command line arguments.
     m_binaryname = std::string(argv[0]);
     setBinaryBasename();
 
-    /* Get the command manager. */
-    CmdManager* mgr = CmdManager::instance();
-
-    /* Tokenize the command line arguments. */
-    mgr->fillCmdArgs( argc, argv );
-
-    /* 
-     * Create a queue of G4 commands from the command-line arguments. 
-     */
-    mgr->fillG4CmdQueue();
+    // Process arguments using the CommandLineProcessor.
+    CommandLineProcessor* cmd = CommandLineProcessor::instance();
+    cmd->process(argc, argv);
   }
 
   void G4Application::initialize()
@@ -173,36 +163,36 @@
       m_isInitialized = true;
     }
     else {
-      cerr << "WARNING: G4Application is already initialized!" << endl;
+      cerr << "WARNING: Command was ignored.  G4Application is already initialized!" << endl;
     }
   }
 
 #ifndef G4UI_NONE
   void G4Application::initializeUI()
   {
-    /* Use tcsh terminal. */
+    // A tcsh terminal.
 #ifdef G4UI_USE_TCSH
     m_session = new G4UIterminal(new G4UItcsh);
 
-    /* Use csh terminal. */
+    // A csh terminal.
 #elif G4UI_USE_CSH
     m_session = new G4UIterminal(new G4UIcsh);
 
-    /* Use GAG. */
+    // GAG.
 #elif G4UI_USE_GAG
     session = new G4UIGAG;
 
-    /* Use Motif. */
+    // Motif GUI.
 #elif G4UI_USE_XM
     m_session = new G4UIXm( 0, NULL );
 
-    /* Add file and exit buttons to Motif UI. */
+    // 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. */
+    // Plain terminal is the fallback.
 #else
     m_session = new G4UIterminal();
 #endif
@@ -303,76 +293,40 @@
 
   void G4Application::run()
   {
-    // Get the command manager.
-    CmdManager* cmgr = CmdManager::instance();
-    
-    // Print version was selected.
-    if (cmgr->isPrintVersion()) {
-      printVersion(std::cout);
-    }
-    // Print usage was selected.
-    else if (cmgr->isPrintUsage()) {
-      printUsage(std::cout);
+    // Initialize if not already.
+    if (!m_isInitialized) {
+      initialize();
     }
-    else {
-      // Initialize.
-      if (!m_isInitialized) {
-	initialize();
-      }
 
-      cout << endl;
+    // Spacer.
+    cout << endl;
 
-      // Execute the queue of Geant4 commands built from command-line arguments.
-      cmgr->execCurrG4CmdQueue(true);
+    // Retrieve the list of Geant4 commands created by CommandLineProcessor.
+    CommandQueue* q = CommandLineProcessor::instance()->getCommandQueue();
 
-      // Start the UI session if in interactive mode.
+    // Print, execute, and clear the CommandQueue.
+    q->printOut(std::cout);
+    q->execute();
+    q->clear();
+    
+    // Start the UI session if in interactive mode.
 #ifndef G4UI_NONE
-      if ( getMode() == eInteractive ) {
-	m_session->SessionStart();
-      }
-#endif
-
-      ModuleRegistry::instance()->deleteModules();
+    if ( getMode() == eInteractive ) {
+      m_session->SessionStart();
     }
-  }
-
-  void G4Application::printUsage(std::ostream& os)
-  {
-    printVersion(os);
-
-    os << std::endl;
-    os << "**************" << std::endl;
-    os << "* SLIC Usage *" << std::endl;
-    os << "**************" << std::endl;
-
-    os << std::endl;
-    os << "Command line usage: " << std::endl;
-    os << std::endl;
-    os << "slic [single_macro_path]" << std::endl;
-    os << "slic [options]" << std::endl;
-
-    os << std::endl;
-
-    os << "Interactive usage: " << std::endl;
-    os << std::endl;
-    os << "slic -n" << std::endl;
-
-    os << std::endl;
-
-    // print out cmd registry
-    CmdManager::instance()->getCmdRegistry()->printOut( os );
-
-    os << std::endl;
+#endif
+    
+    // Done, so delete all the modules.
+    ModuleRegistry::instance()->deleteModules();
   }
 
   void G4Application::printVersion(std::ostream& os)
   {
-    os << PackageInfo::getFullApplicationString() << std::endl;
+    CommandLineProcessor::instance()->printVersion( os );
   }
 
   void G4Application::printSplashScreen(std::ostream& os) const
   {
-    // splash screen
     os << "*************************************************************" << endl;
     os << " App     : " << PackageInfo::getNameString() << " (" << PackageInfo::getAbbrevString() << ")" << endl;
     os << " Version : " << PackageInfo::getVersionString() << endl;
@@ -385,141 +339,9 @@
     os << endl;
   }
 
-  void G4Application::registerCmdLineOpts()
+  void G4Application::printUsage(std::ostream& os)
   {
-    CmdManager* cmd_mgr = CmdManager::instance();
-
-    /* Print application usage. */
-    CmdLineOpt* cmd_usage = new CmdLineOpt("h",
-					   "help",
-					   "Print SLIC usage.",
-					   0,
-					   0);
-    cmd_mgr->addCmd(cmd_usage, "/slic/usage" );
-
-    /* Run in interactive mode. */
-    CmdLineOpt* cmd_iact = new CmdLineOpt("n",
-					  "interactive",
-					  "Start a Geant4 interactive session.",
-					  0,
-					  0);
-    cmd_mgr->addCmd(cmd_iact, "/control/interactive");
-
-    /* Print SLIC version info. */
-    CmdLineOpt* cmd_version = new CmdLineOpt("v",
-					     "version",
-					     "Print SLIC version.",
-					     0,
-					     0);
-    cmd_mgr->addCmd(cmd_version, "/slic/version");
-
-    /* Execute the commands found in a macro file. */
-    CmdLineOpt* cmd_exec = new CmdLineOpt("m",
-					  "macro",
-					  "Execute Geant4 commands from a file.",
-					  1,
-					  1);
-    cmd_mgr->addCmd(cmd_exec, "/control/execute" );
-
-    /* Set the URL of the input LCDD file. */
-    CmdLineOpt* cmd_lcddURL = new CmdLineOpt("g",
-					     "lcdd-url",
-					     "Set LCDD geometry file URL.",
-					     1,
-					     1);
-    cmd_mgr->addCmd(cmd_lcddURL, "/lcdd/url" );
-
-    /* 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.",
-					    1,
-					    1 );
-
-    cmd_mgr->addCmd(cmd_stdhep, "/generator/filename" );
-
-    /* Set the name of the LCIO output file. */
-    CmdLineOpt* cmd_lcio = new CmdLineOpt("o",
-					  "lcio-file",
-					  "Set name of LCIO output file.",
-					  1,
-					  1);
-    cmd_mgr->addCmd(cmd_lcio, "/lcio/filename" );
-
-    /* Set the path of output files. */
-    CmdLineOpt* cmd_lcio_path = new CmdLineOpt("p",
-					       "lcio-path",
-					       "Set directory for LCIO output.",
-					       1,
-					       1);
-    cmd_mgr->addCmd(cmd_lcio_path, "/lcio/path" );
-
-    /*
-     * Automatically name the LCIO output file.
-     * Customization syntax is supported, as long
-     * as spaces are escaped.
-     */
-    CmdLineOpt* cmd_autoname = new CmdLineOpt("O",
-					      "autoname",
-					      "Automatically name the LCIO output file.",
-					      0,
-					      1);
-    cmd_mgr->addCmd(cmd_autoname, "/lcio/autoname" );
-
-    /* Overwrite an existing LCIO output file. */
-    CmdLineOpt* delLcio = new CmdLineOpt("x",
-					 "lcio-delete",
-					 "Delete an existing LCIO file.",
-					 0,
-					 0);
-    cmd_mgr->addCmd(delLcio, "/lcio/fileExists delete");
-
-    /* Do BeamOn. */
-    CmdLineOpt* cmd_beamon = new CmdLineOpt("r",
-					    "run-events",
-					    "Run # of events.",
-					    1,
-					    1);
-    cmd_mgr->addCmd(cmd_beamon, "/run/beamOn");
-
-    /* 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.",
-					      1,
-					      1);
-    cmd_mgr->addCmd(cmd_skip_evt, "/generator/skipEvents" );
-
-    /* Set the physics list. */
-    CmdLineOpt* cmd_phys = new CmdLineOpt("l",
-					  "physics-list",
-					  "Set Geant4 physics list.",
-					  1,
-					  1);
-    cmd_mgr->addCmd(cmd_phys, "/physics/select");
-
-    /* Set the name of the log file. */
-    CmdLineOpt* cmd_log = new CmdLineOpt("L",
-					 "log-file",
-					 "Set logfile name.",
-					 0,
-					 0);
-    cmd_mgr->addCmd(cmd_log, "/log/filename");
-
-    /* Seed the random engine. */
-    CmdLineOpt* rndSeed = new CmdLineOpt("d",
-					 "seed",
-					 "Set the random seed.  (No argument seeds with time.)",
-					 0,
-					 1);
-    cmd_mgr->addCmd(rndSeed, "/random/seed");
-
-    // Dump the loaded Geant4 geometry to a GDML file.
-    CmdLineOpt* dumpgdml = new CmdLineOpt("G",
-					  "dump-gdml",
-					  "Dump geometry to GDML file.",
-					  0,
-					  1);
-    cmd_mgr->addCmd(dumpgdml, "/lcdd/dumpGDML");
+    CommandLineProcessor::instance()->printUsage( os );
   }
-}
+
+} // namespace slic

slic/src
CmdManager.cc removed after 1.22
diff -N CmdManager.cc
--- CmdManager.cc	14 Nov 2006 10:27:04 -0000	1.22
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,275 +0,0 @@
-// $Header: /cvs/lcd/slic/src/Attic/CmdManager.cc,v 1.22 2006/11/14 10:27:04 jeremy Exp $
-#include "CmdManager.hh"
-
-#include "G4Application.hh"
-#include "StringUtil.hh"
-
-#include "G4UImanager.hh"
-
-namespace slic
-{
-
-  CmdManager::CmdManager()
-    : Module("CmdManager"),
-      m_printUsage(false),
-      m_printVersion(false)
-  {}
-
-  CmdManager::~CmdManager()
-  {}
-
-  void CmdManager::addCmd(CmdLineOpt* cl, std::string s)
-  {
-    m_cmdRegistry.addCmd( cl, s );
-  }
-
-  void CmdManager::fillG4CmdQueue()
-  {
-    if (m_args.getTokensBegin() == m_args.getTokensEnd()) {
-      setPrintUsage(true);
-      return;
-    }
-
-    std::string curr_g4_cmd;
-    std::string curr_tok;
-    int n_args = 0;
-    int nArgsMin = 0;
-    int nArgsMax = 0;
-    bool first_time = true;
-    CmdLineOpt* lineOpt = 0;
-
-    for (CmdArgs::TokVecType::const_iterator iter = m_args.getTokensBegin();
-	 iter != m_args.getTokensEnd();
-	 iter++) {
-
-      // get next token
-      curr_tok = *iter;
-
-      // is it a single char opt?
-      bool is_opt = isCmdOpt( curr_tok );
-
-      // is it a command name?
-      bool is_name = isCmdName( curr_tok );
-
-      // handle an option
-      if ( is_opt || is_name) {
-
-	/* Check for not enough args to previous switch. */
-	if ( n_args < nArgsMin ) {
-	  G4Exception("Not enough arguments to switch -" + lineOpt->getOpt() );
-	}
-
-	// add current cmd to queue if not first time
-	if ( first_time == false ) {
-
-	  // add cmd to queue
-	  m_cmdQueue.addCmd( curr_g4_cmd );
-
-	  // reset
-	  n_args = 0;
-	  curr_g4_cmd.clear();
-	}
-	// next time will actually add the cmd
-	else {
-	  first_time = false;
-	}
-
-	// handle opt
-	if ( is_opt ) {
-
-	  // remove pre '-'
-	  curr_tok.erase( curr_tok.begin(), curr_tok.begin() + 1);
-
-	  // find cmd by opt
-	  curr_g4_cmd = m_cmdRegistry.findG4CmdStrByOpt( curr_tok );
-
-	  // Got a print usage.
-	  if (curr_g4_cmd == "/slic/usage") {
-	    setPrintUsage(true);
-	    break;
-	  }
-
-	  // Got a print version.
-	  if (curr_g4_cmd == "/slic/version" ) {
-	    setPrintVersion(true);
-	    break;
-	  }
-
-	  lineOpt = m_cmdRegistry.findCmdLineOptByOpt( curr_tok );
-
-	  if ( curr_g4_cmd == std::string("") ) {
-	    G4Exception("Command option not found: " + curr_tok );
-	  }
-	}
-	// handle name
-	else if ( is_name ) {
-
-	  // remove pre "--"
-	  curr_tok.erase( curr_tok.begin(), curr_tok.begin() + 2 );
-
-	  // find cmd by name
-	  curr_g4_cmd = m_cmdRegistry.findG4CmdStrByName( curr_tok );
-	  lineOpt = m_cmdRegistry.findCmdLineOptByName( curr_tok );
-
-	  if ( curr_g4_cmd == std::string("") ) {
-	    G4Exception("Command name not found: --" + curr_tok);
-	  }
-	}
-
-	nArgsMin = lineOpt->getMinArgs();
-	nArgsMax = lineOpt->getMaxArgs();
-      }
-      // handle arg to command or single macro filename
-      else {
-	// try a single macro arg
-	if ( first_time ) {
-	  if ( m_args.getNumTokens() == 1 ) {
-
-	    std::string mac_cmd = "/control/execute " + curr_tok;
-
-	    m_cmdQueue.addCmd( mac_cmd );
-
-	    break;
-	  }
-	  else {
-	    G4Exception("Single *non-option* commandline argument must be the name of a valid G4 macro file.");
-	  }
-	  break;
-	}
-	// append arg to curr cmd if not first time through
-	else {
-	  curr_g4_cmd += ' ' + curr_tok;
-	  n_args++;
-
-	  /* Check for too many args */
-	  if ( n_args > nArgsMax ) {
-	    G4Exception("Too many arguments to switch -" + lineOpt->getOpt() );
-	  }
-	}
-      }
-    }
-
-    /* Check for not enough args to last switch */
-    if ( n_args < nArgsMin ) {
-      G4Exception("Not enough arguments to switch -" + lineOpt->getOpt() );
-    }
-
-    // add last cmd
-    m_cmdQueue.addCmd( curr_g4_cmd );
-  }
-
-  bool CmdManager::isCmdOpt(const std::string& token)
-  {
-    bool is_opt = false;
-
-    const std::string& valid_opt = m_cmdRegistry.getIsInStr();
-
-    // must have len = 2
-    if ( token.length() == 2 ) {
-
-      // look for '-' in first pos
-      if ( token[0] == '-' ) {
-
-	// find pos of valid cmd char from reg
-	int srch_pos = token.find_first_of( valid_opt, 1 );
-
-	// char must be idx 1
-	if ( srch_pos == 1 ) {
-	  is_opt = true;
-	}
-	else {
-	  std::cerr << "Unknown option <" << token << ">." << std::endl;
-	  G4Exception("Option not found in command registry.");
-	}
-      }
-    }
-
-    return is_opt;
-  }
-
-  bool CmdManager::isCmdName(const std::string& token)
-  {
-    bool is_name = false;
-
-    // str must be > 2 for leading "--" and some additional chars
-    if ( token.length() > 2 ) {
-      // first two chars == "--"
-      if ( token.substr(0,2) == "--" ) {
-	std::string lkp_name = token.substr( 2 );
-
-	// if found CmdLineOpt ptr, then it is a valid name
-	if ( m_cmdRegistry.findCmdLineOptByName( lkp_name ) ) {
-	  is_name = true;
-	}
-      }
-    }
-
-    return is_name;
-  }
-
-  void CmdManager::fillCmdArgs(int argc, char** argv)
-  {
-    m_args.fillFromCmdLine( argc, argv );
-  }
-
-  CmdArgs* CmdManager::getCmdArgs()
-  {
-    return &m_args;
-  }
-
-  CmdRegistry* CmdManager::getCmdRegistry()
-  {
-    return &m_cmdRegistry;
-  }
-
-  G4CmdQueue* CmdManager::getG4CmdQueue()
-  {
-    return &m_cmdQueue;
-  }
-
-  void CmdManager::execCurrG4CmdQueue(bool clear_it)
-  {
-    /* Reorder, insert implied commands such as initialize, etc. */
-    m_cmdQueue.prepare();
-
-    /* Print queue before execution. */
-    m_cmdQueue.printOut(std::cout);
-
-    /* Execute the queue. */
-    m_cmdQueue.execCmds();
-
-    /* Clear the queue. */
-    if ( clear_it ) {
-      clearG4CmdQueue();
-    }
-  }
-
-  void CmdManager::clearG4CmdQueue()
-  {
-    m_cmdQueue.clear();
-  }
-
-  bool CmdManager::isPrintUsage() const
-  {
-    return m_printUsage;
-  }
-
-  bool CmdManager::isPrintVersion() const
-  {
-    return m_printVersion;
-  }
-
-  void CmdManager::setPrintVersion(bool b)
-  {
-    m_printVersion=b;
-    clearG4CmdQueue();
-    m_cmdQueue.addCmd("/slic/version");
-  }
-  
-  void CmdManager::setPrintUsage(bool b)
-  {
-    m_printUsage=b;
-    clearG4CmdQueue();
-    m_cmdQueue.addCmd("/slic/usage");
-  }
-}

slic/src
CmdRegistry.cc removed after 1.14
diff -N CmdRegistry.cc
--- CmdRegistry.cc	6 Jun 2006 21:40:15 -0000	1.14
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,159 +0,0 @@
-// $Header: /cvs/lcd/slic/src/Attic/CmdRegistry.cc,v 1.14 2006/06/06 21:40:15 jeremy Exp $
-#include "CmdRegistry.hh"
-
-using namespace std;
-
-namespace slic
-{
-
-  void CmdRegistry::printOut(std::ostream &os) const
-  {
-    os << "************************" << std::endl;
-    os << "* Command Line Options *" << std::endl;
-    os << "************************" << std::endl;
-    os << std::endl;
-
-    static const int opt_width = 8;
-    //static const int mm_width = 10;
-    static const int descr_width = 15;
-    static const int name_width = 16;
-    static const int cmd_width = 24;
-    static const int sep_width = 60;
-
-    os.width(opt_width);
-    os << left << "Option";
-
-    os.width(name_width);
-    os << left << "Full Name";
-
-    //os.width(mm_width);
-    //os << left << "Min Args";
-
-    //os.width(mm_width);
-    //os << left << "Max Args";
-
-    os.width(cmd_width);
-    os << left << "Macro Command";
-
-    os.width(descr_width);
-    os << left << "Description";
-
-    os.fill('-');
-    os.width(sep_width);
-
-    os << std::endl;
-    os << '-' << std::endl;
-
-    os.fill(' ');
-
-    for ( CmdRegType::const_iterator iter = m_cmds.begin();
-	  iter != m_cmds.end();
-	  iter++ ) {
-      CmdLineOpt* cl_opt = iter->first;
-
-      std::string opt_str = "-" + cl_opt->getOpt();
-      os.width(opt_width);
-      os << left << opt_str;
-
-      std::string name_str = "--" + cl_opt->getName();
-      os.width(name_width);
-      os << left << name_str;
-
-      //os.width(mm_width);
-      //os << left << cl_opt->getMinArgs();
-
-      //os.width(mm_width);
-      //os << left << cl_opt->getMaxArgs();
-
-      os.width(cmd_width);
-      os << left << iter->second;
-
-      os.width(descr_width);
-      os << left << cl_opt->getDescription();
-
-      os << std::endl;
-    }
-  }
-
-  void CmdRegistry::deleteCmdLineOpts()
-  {
-    for ( CmdRegType::const_iterator iter = m_cmds.begin();
-	  iter != m_cmds.end();
-	  iter++ ) {
-      delete iter->first;
-    }
-    m_cmds.clear();
-  }
-
-  // insert cmd by copy
-  void CmdRegistry::addCmd(CmdLineOpt* cl, std::string s)
-  {
-    // add to map
-    m_cmds.push_back( CmdOptToG4CmdPair( cl, s ) );
-
-    // add to list of valid str
-    m_isInStr += cl->getOpt();
-  }
-
-  const std::string& CmdRegistry::getIsInStr()
-  {
-    return m_isInStr;
-  }
-
-  // find by opt
-  std::string CmdRegistry::findG4CmdStrByOpt(const std::string& opt)
-  {
-    std::string s("");
-    for ( CmdRegType::const_iterator iter = m_cmds.begin();
-	  iter != m_cmds.end();
-	  iter++ ) {
-      if ( (iter->first)->getOpt() == opt ) {
-	s = iter->second;
-      }
-    }
-    return s;
-  }
-
-  // find by name
-  std::string CmdRegistry::findG4CmdStrByName(const std::string& name)
-  {
-    std::string s("");
-    for ( CmdRegType::const_iterator iter = m_cmds.begin();
-	  iter != m_cmds.end();
-	  iter++ ) {
-      //std::cout << "compare with: " << iter->first->getName() << std::endl;
-      if ( (iter->first)->getName() == name ) {
-	s = iter->second;
-      }
-    }
-    return s;
-  }
-
-  CmdLineOpt* CmdRegistry::findCmdLineOptByName(const std::string& name)
-  {
-    CmdLineOpt* clo = 0;
-    for ( CmdRegType::const_iterator iter = m_cmds.begin();
-	  iter != m_cmds.end();
-	  iter++ ) {
-      if ( (iter->first)->getName() == name ) {
-	clo = iter->first;
-	break;
-      }
-    }
-    return clo;
-  }
-
-  CmdLineOpt* CmdRegistry::findCmdLineOptByOpt(const std::string& opt)
-  {
-    CmdLineOpt* clo = 0;
-    for ( CmdRegType::const_iterator iter = m_cmds.begin();
-	  iter != m_cmds.end();
-	  iter++ ) {
-      if ( (iter->first)->getOpt() == opt ) {
-	clo = iter->first;
-	break;
-      }
-    }
-    return clo;
-  }
-}

slic/src
G4CmdQueue.cc removed after 1.17
diff -N G4CmdQueue.cc
--- G4CmdQueue.cc	6 Jun 2006 21:39:53 -0000	1.17
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,128 +0,0 @@
-// $Header: /cvs/lcd/slic/src/Attic/G4CmdQueue.cc,v 1.17 2006/06/06 21:39:53 jeremy Exp $
-#include "G4CmdQueue.hh"
-
-#include "G4UImanager.hh"
-
-namespace slic
-{
-  void G4CmdQueue::printOut(std::ostream& os) 
-  {
-    std::cout << std::endl;
-    os << "********************" << std::endl;
-    os << "* G4 Command Queue *" << std::endl;
-    os << "********************" << std::endl;
-    for ( CmdVecType::iterator iter = cmdsBegin();
-	  iter != cmdsEnd();
-	  iter++ ) {
-      os << *iter << std::endl;
-    }
-    std::cout << std::endl;
-  }
-
-  void G4CmdQueue::execCmds()
-  {
-    for ( CmdVecType::iterator iter = cmdsBegin();
-	  iter != cmdsEnd();
-	  iter++ ) {
-      std::string cmd = *iter;
-      //      std::cout << "exec cmd: " << cmd << std::endl;
-      G4UImanager::GetUIpointer()->ApplyCommand( cmd );
-    }
-  }
-
-  void G4CmdQueue::prepare()
-  {
-    setInitialize();
-    reorder();
-  }
-
-  void G4CmdQueue::reorder()
-  {
-    reorderBeamOn();
-    //    reorderLimits();
-    reorder_dumpGDML();
-  }
-
-  void G4CmdQueue::reorderBeamOn()
-  {
-    CmdVecType::iterator iter = find_cmd("/run/beamOn");
-    if (iter != cmdsEnd() ) {
-      std::string cmd = (*iter);
-      m_commands.erase(iter);
-      addCmd(cmd);
-    }
-  }
-
-  void G4CmdQueue::reorder_dumpGDML()
-  {
-    CmdVecType::iterator iter = find_cmd("/lcdd/dumpGDML");
-
-    if (iter != cmdsEnd()) {
-      CmdVecType::iterator init = find_init();
-      std::string cmd = (*iter);
-      if (init != cmdsEnd()) {
-	m_commands.erase(iter);
-	m_commands.insert(init, cmd);
-      }
-    }
-  }
-
-  void G4CmdQueue::setInitialize()
-  {
-    bool setupGeom = false;
-    std::string cmd;
-    CmdVecType::iterator lastCmd;
-    for ( CmdVecType::iterator iter = m_commands.begin();
-	  iter != m_commands.end();
-	  iter++ ) {
-
-      cmd = (*iter);
-
-      /*
-       * Initialization should come after all LCDD commands.
-       */
-      if ( cmd.find("/lcdd/") != std::string::npos ) {
-
-	lastCmd = iter;
-
-	/* Require that the geometry location is set to initialize. */
-	if ( cmd.find("/lcdd/url") != std::string::npos ) {
-	  setupGeom = true;
-	}
-      }
-
-      /* Initialize after physics selection. */
-      if ( cmd.find("/physics/select") != std::string::npos ) {
-	lastCmd = iter;
-      }
-
-      /* Use the in-order command if the user provided "-z" arg at CL. */
-      if ( cmd.find("/run/initialize") != std::string::npos ) {
-	return;
-      }
-    }
-
-    lastCmd = lastCmd + 1;
-    if ( setupGeom ) {
-      m_commands.insert(lastCmd, std::string("/run/initialize") );
-    }
-  }
-
-  G4CmdQueue::CmdVecType::iterator G4CmdQueue::find_init()
-  {
-    return find_cmd("/run/initialize");
-  }
-
-  G4CmdQueue::CmdVecType::iterator G4CmdQueue::find_cmd(const std::string& str)
-  {
-    CmdVecType::iterator iter = m_commands.begin();
-    for ( ;
-	  iter != m_commands.end();
-	  iter++ ) {
-      if ( (*iter).find(str) != std::string::npos ) {
-	break;
-      }
-    }
-    return iter;
-  }
-}
CVSspam 0.2.8