|
SLIC
6.1.1
Simulation for the Linear Collider (SLIC) - Geant4 simulation application
|
Command line processor for SLIC that uses getopt. More...
#include <CommandLineProcessor.hh>
Public Types | |
| typedef std::vector< CommandLineProcessor::OptionsPair > | CommandLineArguments |
| typedef std::vector< CommandLineOption * > | OptionsList |
| typedef std::pair< std::string, std::string > | OptionsPair |
Public Types inherited from Module | |
| enum | ModuleStatus { eOkay = 0 , eNotInitialized = 1 , eBadState = 2 , eFatalError = 3 } |
Public Member Functions | |
| CommandLineProcessor () | |
| virtual | ~CommandLineProcessor () |
| CommandQueue * | getCommandQueue () |
| void | printOptions () |
| void | printUsage () |
| void | printVersion () |
| void | process (int argc, char **argv) |
Public Member Functions inherited from Module | |
| virtual | ~Module () |
| virtual void | beginEvent (const G4Event *) |
| virtual void | beginRun (const G4Run *) |
| virtual void | cleanup () |
| bool | deleteOnExit () |
| virtual void | endEvent (const G4Event *) |
| virtual void | endRun (const G4Run *) |
| const std::string & | getName () const |
| ModuleStatus | getStatus () const |
| virtual void | initialize () |
| LogStream & | log () |
| virtual void | postTracking (const G4Track *) |
| virtual void | preTracking (const G4Track *) |
| virtual void | reset () |
| virtual void | stepping (const G4Step *) |
Public Member Functions inherited from Singleton< CommandLineProcessor > | |
| Singleton () | |
| ~Singleton () | |
| void | release () |
Private Member Functions | |
| void | abort () |
| void | addOption (CommandLineOption *option) |
| void | createOptionsString () |
| CommandLineOption * | getCommandLineOption (const std::string &option) |
| bool | hasOption (const std::string &option) |
| void | processOption (const std::string &option) |
| void | processOptions () |
| void | registerOptions () |
Private Attributes | |
| OptionsList | m_cmds |
| CommandLineArguments | m_commandline |
| CommandQueue | m_g4q |
| std::string | m_getoptOptions |
| int | m_help_flag |
| int | m_interactive_flag |
| int | m_version_flag |
Additional Inherited Members | |
Static Public Member Functions inherited from Singleton< CommandLineProcessor > | |
| static CommandLineProcessor * | instance () |
Public Attributes inherited from Module | |
| bool | m_deleteOnExit |
| LogStream * | m_log |
| std::string | m_name |
| ModuleStatus | m_status |
Protected Member Functions inherited from Module | |
| Module (const std::string &name, bool deleteOnExit=true, bool autoRegister=true) | |
Command line processor for SLIC that uses getopt.
Definition at line 28 of file CommandLineProcessor.hh.
| typedef std::vector<CommandLineProcessor::OptionsPair> CommandLineArguments |
CommandLineArguments is the list of options and arguments from the command line.
Definition at line 40 of file CommandLineProcessor.hh.
| typedef std::vector<CommandLineOption*> OptionsList |
OptionsList is a list of CommandLineOption classes describing valid command line switches.
Definition at line 45 of file CommandLineProcessor.hh.
| typedef std::pair<std::string, std::string> OptionsPair |
OptionsPair is a short option name and its associated arguments.
Definition at line 35 of file CommandLineProcessor.hh.
Class constructor.
Definition at line 21 of file CommandLineProcessor.cc.
References CommandLineProcessor::createOptionsString(), and CommandLineProcessor::registerOptions().
|
virtual |
Class destructor.
Definition at line 27 of file CommandLineProcessor.cc.
|
private |
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.
Definition at line 186 of file CommandLineProcessor.cc.
Referenced by CommandLineProcessor::process().
|
private |
Add a command line option describing a command line switch, its full name, description, geant4 command, etc.
| [in] | option | The command line option to add. |
Definition at line 292 of file CommandLineProcessor.cc.
References CommandLineProcessor::m_cmds.
Referenced by CommandLineProcessor::registerOptions().
|
private |
Automatically create the getopt options string from OptionsList and set the m_getoptOptions variable to this value.
Definition at line 451 of file CommandLineProcessor.cc.
References CommandLineOption::getMaxArgs(), CommandLineOption::getMinArgs(), CommandLineOption::getShortName(), CommandLineProcessor::m_cmds, and CommandLineProcessor::m_getoptOptions.
Referenced by CommandLineProcessor::CommandLineProcessor().
|
private |
Find an option specification by its single letter designation (with no '-').
| [in] | option | The option to find. |
Definition at line 429 of file CommandLineProcessor.cc.
References CommandLineProcessor::m_cmds.
Referenced by CommandLineProcessor::processOption().
|
inline |
Get the queue of Geant4 macro commands created from the command line arguments.
Definition at line 97 of file CommandLineProcessor.hh.
References CommandLineProcessor::m_g4q.
|
private |
Returns true if the option was found in the command line arguments.
| [in] | option | The command line option. |
Definition at line 440 of file CommandLineProcessor.cc.
References CommandLineProcessor::m_commandline.
Referenced by CommandLineProcessor::processOptions().
| void printOptions | ( | ) |
Print out the options table.
Definition at line 366 of file CommandLineProcessor.cc.
References LOG::done, CommandLineOption::getDescription(), CommandLineOption::getG4CommandString(), CommandLineOption::getLongName(), LogStream::getOutputStream(), CommandLineOption::getShortName(), Module::log(), CommandLineProcessor::m_cmds, and LOG::okay.
Referenced by CommandLineProcessor::printUsage().
| void printUsage | ( | ) |
Print the usage statement.
Definition at line 159 of file CommandLineProcessor.cc.
References LOG::done, Module::log(), LOG::okay, CommandLineProcessor::printOptions(), and CommandLineProcessor::printVersion().
Referenced by CommandLineProcessor::process().
|
inline |
Print the version information.
Definition at line 88 of file CommandLineProcessor.hh.
References LOG::done, Module::log(), and LOG::okay.
Referenced by CommandLineProcessor::printUsage(), and CommandLineProcessor::process().
| void process | ( | int | argc, |
| char ** | argv | ||
| ) |
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 and that enough arguments were received, before the command is put into CommandLineArguments. After calling process(), the getCommandQueue() function can be used to retrieve the list of Geant4 macro commands that resulted from processing the raw command line arguments.
| [in] | argc | The argument count. |
| [in] | argv | The argument values. |
Definition at line 30 of file CommandLineProcessor.cc.
References CommandLineProcessor::abort(), CommandQueue::add(), LOG::done, Module::log(), CommandLineProcessor::m_commandline, CommandLineProcessor::m_g4q, CommandLineProcessor::m_getoptOptions, CommandLineProcessor::m_help_flag, CommandLineProcessor::m_interactive_flag, CommandLineProcessor::m_version_flag, CommandLineProcessor::printUsage(), CommandLineProcessor::printVersion(), CommandLineProcessor::processOptions(), and LOG::verbose.
Referenced by SlicApplication::initialize().
|
private |
Process a command line switch by adding the corresponding Geant4 macro command to the CommandQueue.
| [in] | option | The option to process. |
Definition at line 262 of file CommandLineProcessor.cc.
References CommandQueue::add(), CommandLineProcessor::getCommandLineOption(), CommandLineOption::getG4CommandString(), CommandLineProcessor::m_commandline, and CommandLineProcessor::m_g4q.
Referenced by CommandLineProcessor::processOptions().
|
private |
Process all the command line arguments in correct order to create the queue of Geant4 commands.
Definition at line 296 of file CommandLineProcessor.cc.
References CommandQueue::add(), CommandLineProcessor::hasOption(), CommandLineProcessor::m_g4q, CommandLineProcessor::m_interactive_flag, and CommandLineProcessor::processOption().
Referenced by CommandLineProcessor::process().
|
private |
Register the list of valid command line options.
Definition at line 190 of file CommandLineProcessor.cc.
References CommandLineProcessor::addOption().
Referenced by CommandLineProcessor::CommandLineProcessor().
|
private |
The list of valid options and their associated meta-data.
Definition at line 173 of file CommandLineProcessor.hh.
Referenced by CommandLineProcessor::addOption(), CommandLineProcessor::createOptionsString(), CommandLineProcessor::getCommandLineOption(), and CommandLineProcessor::printOptions().
|
private |
A vector of options with their arguments.
Definition at line 167 of file CommandLineProcessor.hh.
Referenced by CommandLineProcessor::hasOption(), CommandLineProcessor::process(), and CommandLineProcessor::processOption().
|
private |
A list of Geant4 macro commands filled by processing the command line arguments.
Definition at line 170 of file CommandLineProcessor.hh.
Referenced by CommandLineProcessor::getCommandQueue(), CommandLineProcessor::process(), CommandLineProcessor::processOption(), and CommandLineProcessor::processOptions().
|
private |
The getopt options string, which is created automatically.
Definition at line 181 of file CommandLineProcessor.hh.
Referenced by CommandLineProcessor::createOptionsString(), and CommandLineProcessor::process().
|
private |
Definition at line 176 of file CommandLineProcessor.hh.
Referenced by CommandLineProcessor::process().
|
private |
Definition at line 177 of file CommandLineProcessor.hh.
Referenced by CommandLineProcessor::process(), and CommandLineProcessor::processOptions().
|
private |
Definition at line 178 of file CommandLineProcessor.hh.
Referenced by CommandLineProcessor::process().