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 |
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 }
void BLCMDparam::init | ( | ) | [inline, private] |
virtual G4String BLCMDparam::commandName | ( | ) | [inline, virtual] |
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 G4Exception("param command","un-named arguments ignored", 00109 JustWarning, ""); 00110 } 00111 00112 if(namedArgs.size() > 0) { 00113 BLArgumentMap::iterator i; 00114 for(i=namedArgs.begin(); i!=namedArgs.end(); ++i) { 00115 bool defined = Param.isDefined(i->first); 00116 if(!unset || !defined) { 00117 // check if value is a valid expression 00118 { BLEvaluator e; 00119 G4double v = e.evaluate(i->second); 00120 // e has many symbols that conflict with 00121 // simple symbols (e.g. "C" for Coulomb), so 00122 // require an operator before evaluating as 00123 // an expression 00124 if(e.status() == HepTool::Evaluator::OK && 00125 i->second.find_first_of("+-*/^<>=()!~&%|?") 00126 != i->second.npos) { 00127 char tmp[64]; 00128 snprintf(tmp,sizeof(tmp),"%.8g",v); 00129 Param.setParam(i->first,tmp); 00130 } else { 00131 Param.setParam(i->first,i->second); 00132 } 00133 } 00134 } 00135 // print param definition 00136 G4String indent1(commandName()); 00137 do { indent1 += " "; } 00138 while(indent1.size() < IndentDesc.size()); 00139 indent1 += i->first; 00140 do { indent1 += " "; } 00141 while(indent1.size() < IndentArg.size()); 00142 printf("%s%s%s\n",indent1.c_str(), 00143 Param.getString(i->first).c_str(), 00144 (unset&&defined ? " (already defined)" : "")); 00145 } 00146 } else { 00147 printParam(); 00148 } 00149 00150 return 0; 00151 }
void BLCMDparam::printParam | ( | ) |
printParam() will display all parameters on stdout.
References Param, and BLParam::printParam().
Referenced by command().
00154 { 00155 Param.printParam(); 00156 }
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 }
std::map<G4String,G4String>* BLCMDparam::paramMap [static, private] |
Referenced by init().