#include <BLParam.hh>
The global object Param is used to access parameter values defined via the param command. The param command and the setParam() functions create parameter name/value pairs known to the Param object.
The BLSetParam class can be used to set initial values of parameters.
The internal representation of every value is a G4String, but that can be converted to double or int via get...() functions.
NOTE: the get*() functions are intended to be used during initialization, not during tracking. They perform a format conversion and can be expensive -- a single call to getDouble() in UserSteppingAction() slowed tracking down by MORE THAN A FACTOR OF TEN!
NOTE: static and global constructors CAN use Param; this is explicitly allowed because init() guarantees initialization order.
Public Member Functions | |
BLParam () | |
Constructor. | |
void | printParam () |
printParam() will display all defined parameters on stdout. | |
G4String | getString (G4String name) |
getString() returns the G4String value of a parameter. If name is not defined as a parameter, the environment is searched. Returns "" for unknown parameters, and displays the error on stdout. DO NOT USE DURING TRACKING! | |
G4double | getDouble (G4String name) |
getDouble() returns the G4double value of a parameter. returns -HUGE_VAL for unknown or invalid-format parameters, and displays the error on stdout. DO NOT USE DURING TRACKING! | |
G4int | getInt (G4String name) |
getInt() returns the G4int value of a parameter. returns 0x80000000 for unknown or invalid-format parameters, and displays the error on stdout. DO NOT USE DURING TRACKING! | |
void | setParam (G4String name, G4String value) |
setParam() sets the value of a parameter. DO NOT USE DURING TRACKING! | |
void | setParam (G4String name, G4double value) |
setParam() sets the value of a parameter. DO NOT USE DURING TRACKING! | |
void | setParam (G4String name, G4int value) |
setParam() sets the value of a parameter. DO NOT USE DURING TRACKING! | |
bool | isDefined (G4String name) |
isDefined() returns true if the name has a defined value. | |
G4String | expand (G4String str) |
expand() will expand every $name in str with parameter values. DO NOT USE DURING TRACKING! | |
void | setHelpText (G4String name, G4String text) |
setHelpText() will set help text for a parameter DO NOT USE DURING TRACKING! | |
G4String | getHelpText () |
getHelpText() returns the (complete) help text string. DO NOT USE DURING TRACKING! | |
Static Private Member Functions | |
static void | init () |
Static Private Attributes | |
static std::map< G4String, G4String > * | paramMap |
static std::map< G4String, G4String > * | paramHelpText |
void BLParam::init | ( | ) | [static, private] |
References paramHelpText, and paramMap.
Referenced by BLParam(), getString(), printParam(), setHelpText(), and setParam().
00027 { 00028 if (!paramMap) paramMap = new std::map<G4String,G4String>; 00029 if (!paramHelpText) paramHelpText = new std::map<G4String,G4String>; 00030 }
void BLParam::printParam | ( | ) |
printParam() will display all defined parameters on stdout.
References init().
Referenced by BLCMDoutput::command(), main(), and BLCMDparam::printParam().
00033 { 00034 init(); 00035 printf("\nPARAMETERS:\n"); 00036 std::map<G4String,G4String>::iterator i; 00037 for(i=(*paramMap).begin(); i!=(*paramMap).end(); ++i) 00038 printf("%15s=%s\n",i->first.c_str(),i->second.c_str()); 00039 }
G4String BLParam::getString | ( | G4String | name | ) |
getString() returns the G4String value of a parameter. If name is not defined as a parameter, the environment is searched. Returns "" for unknown parameters, and displays the error on stdout. DO NOT USE DURING TRACKING!
References init(), paramMap, BLCommand::printError(), and setParam().
Referenced by BLCMDtrackermode::callback(), BLCMDtrackermode::command(), BLCMDparam::command(), BLManager::displayVisual(), expand(), getDouble(), main(), BLCMDparticlecolor::PreUserTrackingAction(), and BLManager::setSteppingFormat().
00042 { 00043 init(); 00044 if((*paramMap).count(name) == 0) { 00045 // define it from the environment, if possible 00046 char *p = getenv(name.c_str()); 00047 if(p) { 00048 setParam(name,p); 00049 } else { 00050 BLCommand::printError("ERROR: Unknown parameter '%s'", 00051 name.c_str()); 00052 } 00053 } 00054 return (*paramMap)[name]; // "" if not found 00055 }
G4double BLParam::getDouble | ( | G4String | name | ) |
getDouble() returns the G4double value of a parameter. returns -HUGE_VAL for unknown or invalid-format parameters, and displays the error on stdout. DO NOT USE DURING TRACKING!
References BLEvaluator::evaluate(), and getString().
Referenced by BLCMDrfdevice::argChanged(), BLCMDpillbox::argChanged(), BLGlobalField::BLGlobalField(), BLManager::BLManager(), BLCMDvirtualdetector::command(), BLCMDtune::command(), BLCMDtubs::command(), BLCMDtrap::command(), BLCMDtrackerplane::command(), BLCMDtorus::command(), BLCMDsphere::command(), BLCMDpolycone::command(), BLCMDparticlefilter::command(), BLCMDmultipole::command(), BLCMDlilens::command(), BLCMDidealsectorbend::command(), BLGroup::command(), BLCMDgenericquad::command(), BLCMDgenericbend::command(), BLCMDextrusion::command(), BLCMDcorner::command(), BLCMDbox::command(), BLCMDabsorber::command(), BLCMDvirtualdetector::construct(), BLCMDusertrackfilter::construct(), BLCMDtubs::construct(), BLCMDtrap::construct(), BLCMDtrackerplane::construct(), BLCMDtorus::construct(), BLCMDsphere::construct(), BLCMDpolycone::construct(), BLCMDparticlefilter::construct(), BLCMDlilens::construct(), BLCMDidealsectorbend::construct(), BLGroup::construct(), BLCMDgenericbend::construct(), BLCMDextrusion::construct(), BLCMDcorner::construct(), BLCMDbox::construct(), getInt(), and BLManager::initialize().
00058 { 00059 G4String v = getString(name); 00060 if(v.size() == 0) return -HUGE_VAL; 00061 BLEvaluator e; 00062 G4double val = e.evaluate(v); 00063 if(e.status() != HepTool::Evaluator::OK) return -HUGE_VAL; 00064 return val; 00065 }
G4int BLParam::getInt | ( | G4String | name | ) |
getInt() returns the G4int value of a parameter. returns 0x80000000 for unknown or invalid-format parameters, and displays the error on stdout. DO NOT USE DURING TRACKING!
References getDouble(), and BLCommand::printError().
Referenced by BLKillTrack::BLKillTrack(), BLCMDtrackcuts::command(), BLCMDspacechargelw::command(), BLCMDspacecharge::command(), BLCMDparticlefilter::command(), BLCMDusertrackfilter::construct(), BLManager::initialize(), and MaterialFilter::MaterialFilter().
00068 { 00069 G4double v = getDouble(name); 00070 G4int i = (G4int)(v+0.5); 00071 if(v == -HUGE_VAL || fabs(v-i) > 0.001) 00072 BLCommand::printError("ERROR non-integer value used as int"); 00073 return i; 00074 }
void BLParam::setParam | ( | G4String | name, | |
G4String | value | |||
) |
setParam() sets the value of a parameter. DO NOT USE DURING TRACKING!
References init().
Referenced by BLSetParam::BLSetParam(), BLCMDparam::command(), BLCMDdo::command(), BLCMDcornerarc::command(), getString(), main(), BLGroup::placeElement(), and setParam().
00077 { 00078 init(); 00079 (*paramMap)[name] = value; 00080 }
void BLParam::setParam | ( | G4String | name, | |
G4double | value | |||
) |
setParam() sets the value of a parameter. DO NOT USE DURING TRACKING!
References setParam().
00083 { 00084 char tmp[32]; 00085 sprintf(tmp,"%g",value); 00086 setParam(name,tmp); 00087 }
void BLParam::setParam | ( | G4String | name, | |
G4int | value | |||
) |
setParam() sets the value of a parameter. DO NOT USE DURING TRACKING!
References setParam().
00090 { 00091 char tmp[32]; 00092 sprintf(tmp,"%d",value); 00093 setParam(name,tmp); 00094 }
bool BLParam::isDefined | ( | G4String | name | ) |
isDefined() returns true if the name has a defined value.
References paramMap.
Referenced by BLCMDparam::command().
G4String BLParam::expand | ( | G4String | str | ) |
expand() will expand every $name in str with parameter values. DO NOT USE DURING TRACKING!
References getString(), and BLCommand::printError().
Referenced by BLCMDif::command(), Macro::command(), and BLCommand::parseArgs().
00104 { 00105 static G4String nameChars("ABCDEFGHIJKLMNOPQRSTUVWXYZ_" 00106 "abcdefghijklmnopqrstuvwxyz0123456789"); 00107 G4String out; 00108 00109 G4String::size_type place=0; 00110 while(place < str.size()) { 00111 G4String::size_type i=str.find('$',place); 00112 if(i == str.npos) { 00113 out += str.substr(place); 00114 break; 00115 } 00116 out += str.substr(place,i-place); 00117 place = i + 1; 00118 // leave $1 - $9 and $# alone (for define command) 00119 if(isdigit(str[place]) || str[place] == '#') { 00120 out += "$"; 00121 continue; 00122 } 00123 // replace $$ with $ (delayed evaluation of $param) 00124 if(str[place] == '$') { 00125 out += "$"; 00126 ++place; 00127 continue; 00128 } 00129 G4String::size_type j=str.find_first_not_of(nameChars,place); 00130 if(j == str.npos) j = str.size(); 00131 G4String name=str.substr(place,j-place); 00132 if(j == place || isdigit(str[place])) 00133 BLCommand::printError("ERROR: Invalid parameter name '%s'", 00134 name.c_str()); 00135 else 00136 out += getString(name); 00137 place = j; 00138 } 00139 00140 return out; 00141 }
void BLParam::setHelpText | ( | G4String | name, | |
G4String | text | |||
) |
setHelpText() will set help text for a parameter DO NOT USE DURING TRACKING!
References init().
Referenced by BLSetParam::BLSetParam().
00144 { 00145 init(); 00146 (*paramHelpText)[name] = text; 00147 }
G4String BLParam::getHelpText | ( | ) |
getHelpText() returns the (complete) help text string. DO NOT USE DURING TRACKING!
Referenced by BLCMDhelp::command(), and BLCMDparam::help().
00150 { 00151 G4String s; 00152 std::map<G4String,G4String>::iterator i; 00153 for(i=(*paramHelpText).begin(); i!=(*paramHelpText).end(); ++i) { 00154 G4String::size_type n = s.size(); 00155 s += " "; 00156 s += i->first; 00157 s += " "; 00158 while(s.size()-n < 24) s += " "; 00159 s += i->second; 00160 s += "\n"; 00161 } 00162 00163 return s; 00164 }
std::map< G4String, G4String > * BLParam::paramMap [static, private] |
Referenced by getString(), init(), and isDefined().
std::map< G4String, G4String > * BLParam::paramHelpText [static, private] |
Referenced by init().