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("'param name=value ...' defines parameters.\n" 00072 "If no arguments are present, all parameters are displayed.\n" 00073 "If the first parameter is '-unset', this command will not\n" 00074 "overwrite parameters that are already set (e.g. from the\n" 00075 "command line - this permits the input.file to set defaults " 00076 "that can be overridden on the command line).\n" 00077 "Parameters can be used in arguments of commands:\n" 00078 "'cmd argname=$paramname [...]'\n" 00079 "Parameters can be set from the command line, as all arguments\n" 00080 "after the first are interpreted as paramname=value.\n" 00081 "This is most useful for setting global things like viewer\n" 00082 "and histoFile, or parameters used in input.file.\n" 00083 "The values of parameters are strings, but if the value of a " 00084 "parameter is a valid real expression including at least one " 00085 "operator {+-*/^<>=()!~&%|?}, the parameter value will " 00086 "be set to the numerical value of the expression to 8 significant " 00087 "digits.\n\n" 00088 "NOTE: pre-defined Prograom control parameters (listed below) " 00089 "are defined before the command-line and are not affected by -unset."); 00090 }
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.
00093 { 00094 bool unset = false; 00095 00096 if(argv.size() > 0 && argv[0] == "-unset") { 00097 unset = true; 00098 } 00099 if(argv.size() > (unset ? 1 : 0)) { 00100 printf("param: WARNING un-named arguments ignored.\n"); 00101 } 00102 00103 if(namedArgs.size() > 0) { 00104 BLArgumentMap::iterator i; 00105 for(i=namedArgs.begin(); i!=namedArgs.end(); ++i) { 00106 bool defined = Param.isDefined(i->first); 00107 if(!unset || !defined) { 00108 // check if value is a valid expression 00109 { BLEvaluator e; 00110 G4double v = e.evaluate(i->second); 00111 // e has many symbols that conflict with 00112 // simple symbols (e.g. "C" for Coulomb), so 00113 // require an operator before evaluating as 00114 // an expression 00115 if(e.status() == HepTool::Evaluator::OK && 00116 i->second.find_first_of("+-*/^<>=()!~&%|?") 00117 != i->second.npos) { 00118 char tmp[64]; 00119 snprintf(tmp,sizeof(tmp),"%.8g",v); 00120 Param.setParam(i->first,tmp); 00121 } else { 00122 Param.setParam(i->first,i->second); 00123 } 00124 } 00125 } 00126 // print param definition 00127 G4String indent1(commandName()); 00128 do { indent1 += " "; } 00129 while(indent1.size() < IndentDesc.size()); 00130 indent1 += i->first; 00131 do { indent1 += " "; } 00132 while(indent1.size() < IndentArg.size()); 00133 printf("%s%s%s\n",indent1.c_str(), 00134 Param.getString(i->first).c_str(), 00135 (unset&&defined ? " (already defined)" : "")); 00136 } 00137 } else { 00138 printParam(); 00139 } 00140 00141 return 0; 00142 }
void BLCMDparam::printParam | ( | ) |
printParam() will display all parameters on stdout.
References Param, and BLParam::printParam().
Referenced by command().
00145 { 00146 Param.printParam(); 00147 }
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().