BLCMDparam Class Reference

Inheritance diagram for BLCMDparam:

BLCommand

List of all members.


Detailed Description

class BLCMDparam implements the param command.

Public Member Functions

 BLCMDparam ()
 Constructor. registers the command and provides help text.
virtual G4String commandName ()
 commandName() returns "param";
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
 command() implements the param command. It does not use the standard handleNamedArgs(), but accepts any named argument and defines a parameter of that name. Unnamed args are ignored with a warning. If no args are present, calls printParam().
void printParam ()
 printParam() will display all parameters on stdout.
virtual void help (bool detailed)

Private Member Functions

void init ()

Static Private Attributes

static std::map< G4String,
G4String > * 
paramMap

Constructor & Destructor Documentation

BLCMDparam::BLCMDparam (  ) 

Constructor. registers the command and provides help text.

References BLCMDTYPE_CONTROL, BLCommand::registerCommand(), BLCommand::setDescription(), and BLCommand::setSynopsis().

00068 {
00069         registerCommand(BLCMDTYPE_CONTROL);
00070         setSynopsis("Defines parameter values.");
00071         setDescription("Parameters are named strings used to parameterize "
00072             "the input file; a few are used for program control.\n"
00073             "Parameters are set by the param commend, and on the command "
00074             "line (all program arguments after the first are interpreted "
00075             "as name=value).\n\n"
00076             "'param name=value ...' defines parameters.\n"
00077             "If no arguments are present, all parameters are displayed. "
00078             "If the first argument is '-unset', this command will not\n"
00079             "overwrite parameters that are already set (e.g. from the\n"
00080             "command line - this permits the input.file to set defaults "
00081             "that can be overridden on the command line).\n\n"
00082             "Parameters are expanded only in the arguments of commands:\n"
00083             "'cmd argname=$paramname [...]'; real-valued expressions for "
00084             "arguments can use $paramname as a value, as long as paramname "
00085             "contains a valid real expression.\n\n"
00086             "Parameters are most useful for setting global things like viewer\n"
00087             "and histoFile, or as parameters used in the input.file.\n\n"
00088             "When a parameter is used, if it has not been defined, it will "
00089             "be defined from the environment if possible; if it is not defined "
00090             "in the environment then this generates an error message.\n\n"
00091             "The values of parameters are strings, but if the value of a "
00092             "parameter is set to a valid real expression including at least "
00093             "one operator {+-*/^<>=()!~&%|?}, the parameter value will "
00094             "be set to the numerical value of the expression to 8 significant "
00095             "digits.\n\n"
00096             "NOTE: pre-defined Program control parameters (listed below) are "
00097             "defined before the command-line and are not affected by -unset.");
00098 }


Member Function Documentation

void BLCMDparam::init (  )  [inline, private]

References paramMap.

00037 {if (!paramMap) paramMap = new std::map<G4String,G4String>;}

virtual G4String BLCMDparam::commandName (  )  [inline, virtual]

commandName() returns "param";

Implements BLCommand.

Referenced by command().

00043 { return "param"; }

int BLCMDparam::command ( BLArgumentVector argv,
BLArgumentMap namedArgs 
) [virtual]

command() implements the param command. It does not use the standard handleNamedArgs(), but accepts any named argument and defines a parameter of that name. Unnamed args are ignored with a warning. If no args are present, calls printParam().

Implements BLCommand.

References commandName(), BLEvaluator::evaluate(), BLParam::getString(), IndentArg(), IndentDesc(), BLParam::isDefined(), Param, printParam(), BLParam::setParam(), and snprintf.

00101 {
00102         bool unset = false;
00103 
00104         if(argv.size() > 0 && argv[0] == "-unset") {
00105                 unset = true;
00106         }
00107         if(argv.size() > (unset ? 1 : 0)) {
00108                 printf("param: WARNING un-named arguments ignored.\n");
00109         }
00110 
00111         if(namedArgs.size() > 0) {
00112                 BLArgumentMap::iterator i;
00113                 for(i=namedArgs.begin(); i!=namedArgs.end(); ++i) {
00114                         bool defined = Param.isDefined(i->first);
00115                         if(!unset || !defined) {
00116                                 // check if value is a valid expression
00117                                 { BLEvaluator e;
00118                                   G4double v = e.evaluate(i->second);
00119                                   // e has many symbols that conflict with
00120                                   // simple symbols (e.g. "C" for Coulomb), so
00121                                   // require an operator before evaluating as
00122                                   // an expression
00123                                   if(e.status() == HepTool::Evaluator::OK &&
00124                                      i->second.find_first_of("+-*/^<>=()!~&%|?")
00125                                                         != i->second.npos) {
00126                                         char tmp[64];
00127                                         snprintf(tmp,sizeof(tmp),"%.8g",v);
00128                                         Param.setParam(i->first,tmp);
00129                                   } else {
00130                                         Param.setParam(i->first,i->second);
00131                                   }
00132                                 }
00133                         }
00134                         // print param definition
00135                         G4String indent1(commandName());
00136                         do { indent1 += " "; }
00137                                 while(indent1.size() < IndentDesc.size());
00138                         indent1 += i->first;
00139                         do { indent1 += " "; }
00140                                 while(indent1.size() < IndentArg.size());
00141                         printf("%s%s%s\n",indent1.c_str(),
00142                                 Param.getString(i->first).c_str(),
00143                                 (unset&&defined ? "  (already defined)" : ""));
00144                 }
00145         } else {
00146                 printParam();
00147         }
00148 
00149         return 0;
00150 }

void BLCMDparam::printParam (  ) 

printParam() will display all parameters on stdout.

References Param, and BLParam::printParam().

Referenced by command().

00153 {
00154         Param.printParam();
00155 }

virtual void BLCMDparam::help ( bool  detailed  )  [inline, virtual]

Reimplemented from BLCommand.

References BLParam::getHelpText(), BLManager::getObject(), BLCommand::help(), and Param.

00054                                          {
00055                 BLCommand::help(detailed);
00056                 if(detailed) {
00057                     printf("\nProgram control Parameters:\n%s",
00058                                                 Param.getHelpText().c_str());
00059                     printf("steppingFormat is a space- or comma-separated list of items:\n%s\n\n",
00060                         BLManager::getObject()->getFormatHelp().c_str());
00061                 }
00062         }


Member Data Documentation

std::map<G4String,G4String>* BLCMDparam::paramMap [static, private]

Referenced by init().


The documentation for this class was generated from the following file:
g4beamline