BLParam Class Reference

#include <BLParam.hh>

List of all members.


Detailed Description

BLParam - parameter class.

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


Constructor & Destructor Documentation

BLParam::BLParam (  )  [inline]

Constructor.

References init().

00052 { init(); }


Member Function Documentation

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 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. returns "" for unknown parameters, and displays the error on stdout. DO NOT USE DURING TRACKING!

References init(), paramMap, and BLCommand::printError().

Referenced by BLCMDparam::command(), BLManager::displayVisual(), expand(), getDouble(), main(), BLCMDparticlecolor::PreUserTrackingAction(), and BLManager::setSteppingFormat().

00042 {
00043         init();
00044         if((*paramMap).count(name) == 0)
00045                 BLCommand::printError("ERROR: Unknown parameter '%s'",
00046                                                 name.c_str());
00047         return (*paramMap)[name];       // "" if not found
00048 }

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 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(), 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(), BLCMDidealsectorbend::construct(), BLGroup::construct(), BLCMDgenericbend::construct(), BLCMDextrusion::construct(), BLCMDcorner::construct(), BLCMDbox::construct(), getInt(), and BLManager::initialize().

00051 {
00052         G4String v = getString(name);
00053         if(v.size() == 0) return -HUGE_VAL;
00054         BLEvaluator e;
00055         G4double val = e.evaluate(v);
00056         if(e.status() != HepTool::Evaluator::OK) return -HUGE_VAL;
00057         return val;
00058 }

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(), BLCMDparticlefilter::command(), BLCMDcollective::command(), BLCMDusertrackfilter::construct(), and BLManager::initialize().

00061 {
00062         G4double v = getDouble(name);
00063         G4int i = (G4int)(v+0.5);
00064         if(v == -HUGE_VAL || fabs(v-i) > 0.001)
00065                 BLCommand::printError("ERROR non-integer value used as int");
00066         return i;
00067 }

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(), main(), BLGroup::placeElement(), and setParam().

00070 {
00071         init();
00072         (*paramMap)[name] = value;
00073 }

void BLParam::setParam ( G4String  name,
G4double  value 
)

setParam() sets the value of a parameter. DO NOT USE DURING TRACKING!

References setParam().

00076 {
00077         char tmp[32];
00078         sprintf(tmp,"%g",value);
00079         setParam(name,tmp);
00080 }

void BLParam::setParam ( G4String  name,
G4int  value 
)

setParam() sets the value of a parameter. DO NOT USE DURING TRACKING!

References setParam().

00083 {
00084         char tmp[32];
00085         sprintf(tmp,"%d",value);
00086         setParam(name,tmp);
00087 }

bool BLParam::isDefined ( G4String  name  ) 

isDefined() returns true if the name has a defined value.

References paramMap.

Referenced by BLCMDparam::command().

00090 {
00091         if(paramMap)
00092                 return paramMap->count(name) != 0;
00093         return false;
00094 }

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

00097 {
00098         static G4String nameChars("ABCDEFGHIJKLMNOPQRSTUVWXYZ_"
00099                                   "abcdefghijklmnopqrstuvwxyz0123456789");
00100         G4String out;
00101 
00102         unsigned place=0;
00103         while(place < str.size()) {
00104                 unsigned i=str.find('$',place);
00105                 if(i == str.npos) {
00106                         out += str.substr(place);
00107                         break;
00108                 }
00109                 out += str.substr(place,i-place);
00110                 place = i + 1;
00111                 // leave $1 - $9 and $# alone (for define command)
00112                 if(isdigit(str[place]) || str[place] == '#') {
00113                         out += "$";
00114                         continue;
00115                 }
00116                 // replace $$ with $ (delayed evaluation of $param)
00117                 if(str[place] == '$') {
00118                         out += "$";
00119                         ++place;
00120                         continue;
00121                 }
00122                 unsigned j=str.find_first_not_of(nameChars,place);
00123                 if(j == str.npos) j = str.size();
00124                 G4String name=str.substr(place,j-place);
00125                 if(j == place || isdigit(str[place]))
00126                     BLCommand::printError("ERROR: Invalid parameter name '%s'",
00127                                                         name.c_str());
00128                 else
00129                     out += getString(name);
00130                 place = j;
00131         }
00132 
00133         return out;
00134 }

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

00137 {
00138         init();
00139         (*paramHelpText)[name] = text;
00140 }

G4String BLParam::getHelpText (  ) 

getHelpText() returns the (complete) help text string. DO NOT USE DURING TRACKING!

Referenced by BLCMDhelp::command(), and BLCMDparam::help().

00143 {
00144         G4String s;
00145         std::map<G4String,G4String>::iterator i;
00146         for(i=(*paramHelpText).begin(); i!=(*paramHelpText).end(); ++i) {
00147                 unsigned n = s.size();
00148                 s += "    ";
00149                 s += i->first;
00150                 s += " ";
00151                 while(s.size()-n < 24) s += " ";
00152                 s += i->second;
00153                 s += "\n";
00154         }
00155 
00156         return s;
00157 }


Member Data Documentation

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


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