SLIC  6.1.1
Simulation for the Linear Collider (SLIC) - Geant4 simulation application
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CommandLineProcessor Class Reference

Command line processor for SLIC that uses getopt. More...

#include <CommandLineProcessor.hh>

Inheritance diagram for CommandLineProcessor:
Module Singleton< CommandLineProcessor >

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)
 

Detailed Description

Command line processor for SLIC that uses getopt.

Author
Jeremy McCormick
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.

Definition at line 28 of file CommandLineProcessor.hh.

Member Typedef Documentation

◆ CommandLineArguments

CommandLineArguments is the list of options and arguments from the command line.

Definition at line 40 of file CommandLineProcessor.hh.

◆ OptionsList

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.

◆ OptionsPair

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.

Constructor & Destructor Documentation

◆ CommandLineProcessor()

◆ ~CommandLineProcessor()

~CommandLineProcessor ( )
virtual

Class destructor.

Definition at line 27 of file CommandLineProcessor.cc.

Member Function Documentation

◆ abort()

void abort ( )
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().

◆ addOption()

void addOption ( CommandLineOption *  option)
private

Add a command line option describing a command line switch, its full name, description, geant4 command, etc.

Parameters
[in]optionThe command line option to add.

Definition at line 292 of file CommandLineProcessor.cc.

References CommandLineProcessor::m_cmds.

Referenced by CommandLineProcessor::registerOptions().

◆ createOptionsString()

void createOptionsString ( )
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().

◆ getCommandLineOption()

CommandLineOption * getCommandLineOption ( const std::string &  option)
private

Find an option specification by its single letter designation (with no '-').

Parameters
[in]optionThe option to find.
Returns
The command line option object or null if does not exist.

Definition at line 429 of file CommandLineProcessor.cc.

References CommandLineProcessor::m_cmds.

Referenced by CommandLineProcessor::processOption().

◆ getCommandQueue()

CommandQueue* getCommandQueue ( )
inline

Get the queue of Geant4 macro commands created from the command line arguments.

Returns
The queue of Geant4 macro commands to execute.

Definition at line 97 of file CommandLineProcessor.hh.

References CommandLineProcessor::m_g4q.

◆ hasOption()

bool hasOption ( const std::string &  option)
private

Returns true if the option was found in the command line arguments.

Parameters
[in]optionThe command line option.
Returns
True if option exist; false if not.

Definition at line 440 of file CommandLineProcessor.cc.

References CommandLineProcessor::m_commandline.

Referenced by CommandLineProcessor::processOptions().

◆ printOptions()

void printOptions ( )

◆ printUsage()

void printUsage ( )

◆ printVersion()

void printVersion ( )
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().

◆ 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.

Parameters
[in]argcThe argument count.
[in]argvThe 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().

◆ processOption()

void processOption ( const std::string &  option)
private

Process a command line switch by adding the corresponding Geant4 macro command to the CommandQueue.

Parameters
[in]optionThe 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().

◆ processOptions()

void 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().

◆ registerOptions()

void registerOptions ( )
private

Register the list of valid command line options.

Definition at line 190 of file CommandLineProcessor.cc.

References CommandLineProcessor::addOption().

Referenced by CommandLineProcessor::CommandLineProcessor().

Member Data Documentation

◆ m_cmds

OptionsList m_cmds
private

◆ m_commandline

CommandLineArguments m_commandline
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().

◆ m_g4q

CommandQueue m_g4q
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().

◆ m_getoptOptions

std::string m_getoptOptions
private

The getopt options string, which is created automatically.

Definition at line 181 of file CommandLineProcessor.hh.

Referenced by CommandLineProcessor::createOptionsString(), and CommandLineProcessor::process().

◆ m_help_flag

int m_help_flag
private

Definition at line 176 of file CommandLineProcessor.hh.

Referenced by CommandLineProcessor::process().

◆ m_interactive_flag

int m_interactive_flag
private

◆ m_version_flag

int m_version_flag
private

Definition at line 178 of file CommandLineProcessor.hh.

Referenced by CommandLineProcessor::process().


The documentation for this class was generated from the following files: