#include <BLCommand.hh>
The standard usage for a command without a BLElement is to derive from this class and define a static instance using the default constructor. In the derived-class default constructor the command is registered, calls to setSynopsis() and setDescription() provide help text, and initial values are given to all class variables. This instance is used to execute the command, and normally no other instances are needed.
The static instance is used to keep the default arguments for the element.
Standard usage for a command for a BLElement is to derive a class from BLElement (which is derived from BLCommand), and do the above in its default constructor. The derived command() function then creates an instance of the class. Only the static instance is used to execute the command, but other instances implement the various elements (to be placed later in the input file).
See BLCMDdemo.cc and BLCMDtubs.cc for examples (.hh files are not needed for most commands, as their classes are not needed anywhere but in their implementation file).
NOTE: ONLY the default object should use the default constructor!
Public Member Functions | |
virtual G4String | commandName ()=0 |
commandName() returns the name of the command. | |
virtual int | command (BLArgumentVector &argv, BLArgumentMap &namedArgs)=0 |
command() executes the command associated with this element. argv and namedArgs come from parsing the command-line: argv has a vector of any positional arguments (without "="); namedArgs has a map of any named arguments of the form name=value. Returns 0 if OK, -1 on error. NOTE: for classes derived via BLElement.hh, arguments can be given when an object is defined and when it is placed. For that to work, argument values must not be used in the command() function unless they are defined with permitChange=false (in the above argString... functions). Also the correct units must be given to argDouble(). | |
virtual void | defineNamedArgs () |
defineNamedArgs() defines the named arguments for the command. This function should consist ONLY of a series of calls to argString(), argDouble(), and argInt(). Used by handleNamedArgs(), help(), and print() (they manipulate the behavior of the argXXX() functions via argMode). | |
virtual void | argChanged () |
argChanged() will be called whenever some argument value has changed. Derived classes should define it and perform any internal computations that depend on argument values. Many/most derived classes won't need to use it. In particular, after argChanged() returns the functions getHeight(), getWidth() and getLength() must return the correct values for the current arguments. BEWARE: a single argument change may call this multiple times. Applies only to named arguments, not positional ones. | |
virtual void | print (G4String name) |
print() will print to stdout the command. The default versions will do for most commands and elements. name can be "". prints commandname() and name in the space of IndentArg, followed by the values of all named arguments, in the order they appear in defineNamedArgs(). | |
void | print (G4String name, BLArgumentMap &namedArgs) |
Print() -- alternate version for commands with special arguments. does not use defineNamedArgs() to print arguments, but rather prints namedArgs. | |
virtual G4String | getName () const |
getName() returns the element's name; do not confuse this with commandName(). Re-defined by BLElement. | |
BLCmdType | getCmdType () |
getCmdType() returns the type of this command | |
void | setPos (BLCommandPos &pos) |
setPos() will set the Command input stream to a specified position | |
Static Public Member Functions | |
static bool | isValidCommand (G4String &cmd) |
isValidCommand() returns true if cmd is a valid command. | |
static int | doCommand (G4String &line) |
doCommand() will parse line and perform a single command. Returns 0 if OK, -1 if error. | |
static int | parseArgs (const G4String &line, BLArgumentVector &argv, BLArgumentMap &namedArgs) |
parseArgs() will parse the arguments of a command line. Arguments are appended to argv[] and added to namedArgs. Returns 0 if OK, -1 if syntax error. | |
static int | readFile (G4String filename) |
readFile() reads a file of commands and executes them. "-" is stdin. Returns the number of errors encountered, or -1 if filename cannot be read. | |
static void | printError (const char *fmt,...) |
printError() prints an error message, using sprintf-style args. It also increments the errorCount. | |
static int | getErrorCount () |
getErrorCount() will return the number of errors so far. | |
static G4String * | getNextCommand () |
getNextCommand() returns the next command. backslash-newline has been handled, and the line is stripped of whitespace at both ends. returns 0 if error or EOF. The pointer should NOT be deleted. | |
static BLCommandPos | getPos () |
getPos() returns the current position of the Command input stream | |
static G4Material * | getMaterial (G4String materialName, bool error=true) |
getMaterial() searches the G4Material list and returns the entry corresponding to name. Searches the NIST database if the material is not already defined. Prepends "G4_" if necessary. prints an error and exits if the material is not found, so all materials MUST be defined before they are used, unless they can be found in the geant4 NIST database. | |
static G4VisAttributes * | getVisAttrib (G4String color) |
getVisAttrib() returns the appropriate G4VisAttributes. | |
static G4RotationMatrix * | stringToRotationMatrix (G4String rotation) |
stringToRotationMatrix() converts a string "X90,Y45" into a G4RotationMatrix. This is an active rotation, in that the object is first rotated around the parent's X axis by 90 degrees, then the object is further rotated around the parent's Y axis by 45 degrees. The return value points to a G4RotationMatrix on the heap, so it is persistent. Angles are in degrees, can have decimals, and can be negative. Axes are X, Y, Z. | |
static void | dumpRotation (const G4RotationMatrix *rot, const char *str) |
dumpRotation() dumps info about a rotation matrix to stdout. | |
static std::vector< G4String > | splitString (const G4String &s, const G4String &delim, bool trim=false) |
splitString() splits a string at each instance of any character in delim, returning a vector<G4String>. If trim is true, each returned string has whitespace removed from its front and rear. Successive delimiters, or delimiters at the beginning or end, generate an empty string. | |
static double | getDouble (const G4String &s) |
getDouble() converts a string to a double, returning nan if the string is not a valid expression using double constants and standard C operators and functions; whitespace is permitted as in C but an empty or all-whitespace string is invalid. Callers can use std::isnan(double) or gsl_isnan(double) to test for validity. | |
static std::vector< G4double > | getList (const G4String &s, const G4String &delim) |
getList() converts a string containing a delimited list of double expressions to a vector<G4double>. Any character in delim separates entries. Functions and operators known to BLEvaluator can be used in each entry of the list. Empty entries (null or consisting only of whitespace) are invalid. Returns an empty list if any entry is an invalid expression. | |
Protected Types | |
enum | ArgumentMode { PROCESS, COUNT, HELP, PRINT, CHANGE } |
Protected Member Functions | |
BLCommand () | |
Default Constructor. | |
virtual | ~BLCommand () |
Destructor. | |
BLCommand (const BLCommand &r) | |
Copy Constructor. | |
void | registerCommand (BLCmdType _type) |
registerCommand() registers the command. Used only in the default constructor -- ensures mapCommand is properly initialized regardless of order. | |
void | deleteCommand (G4String &name) |
deleteCommand() will delete a command by name | |
void | setSynopsis (const char *_synopsis) |
setSynopsis() gives a 1-line (64 char) description of what the command does. Used by the help command with no arguments. The string should be 64 characters or less, and should not contain any newline; no word wrapping. Used only in the default constructor. | |
void | setDescription (const char *_description) |
setDescription() gives a more complete description of the command, when help for this specific command is requested. When printed by the help() function, word wrapping is performed, but lines beginning with whitespace are kept intact. Named arguments are automatically described by the help() function, but positional arguments should be described here. Words are wrapped using wrapWords(). Used only in the default constructor. | |
void | argString (G4String &var, G4String name, G4String description, bool permitChange=true) |
argString() declares a string-valued argument. name should be a valid C identifier 15 chars or less, and description should be a short description (wrapWords() is used). Used only in the defineNamedArgs() function. permitChange affects whether this argument can be set when an element is placed. | |
void | argDouble (G4double &var, G4String name, G4String description, G4double units=1.0, G4String fmt=DefaultDoubleFmt, bool permitChange=true) |
argDouble() declares a G4double-valued argument. name should be a valid C identifier 15 chars or less, and description should be a short description (wrapWords() is used). Used only in the defineNamedArgs() function. units should be the human units for the argument, because the value of var is always in internal units. fmt and units are used when argMode=PRINT. permitChange affects whether this argument can be set when an element is placed. | |
void | argTunable (G4double &var, G4String name, G4String description, G4double units=1.0, G4String fmt=DefaultDoubleFmt) |
argTunable() declares a G4double-valued argument that is tunable (see the tune command in BLCMDtune.cc). name should be a valid C identifier 15 chars or less, and description should be a short description (wrapWords() is used). Used only in the defineNamedArgs() function. units should be the human units for the argument, because the value of var is always in internal units. fmt and units are used when argMode=PRINT. Tunable arguments can always be set when an element is placed, and will be changed during the tracking of the Tune Particle if their value includes a tune variable. See BLTune.hh for a description of how tunable arguments are handled. | |
void | argInt (G4int &var, G4String name, G4String description, bool permitChange=true) |
argInt() declares a integer-valued argument. name should be a valid C identifier 15 chars or less, and description should be a short description (wrapWords() is used). Used only in the defineNamedArgs() function. permitChange affects whether this argument can be set when an element is placed. | |
int | handleNamedArgs (BLArgumentMap &namedArgs) |
handleNamedArgs() handles all named arguments to the command (i.e. those defined in defineNamedArgs()). For use in the command() function. returns 0 if OK, -1 on error. | |
virtual void | help (bool detailed) |
help() prints the help information for this command. detailed=false prints only the name and synopsis; true prints the description and arguments also. | |
G4String | wrapWords (G4String text, G4String indent1, G4String indent, G4String::size_type width=79) |
wrapWords() will wrap words for descriptions in help(). In text, lines beginning with whitespace are preserved as is, including blank lines. Otherwise, newlines aren't needed in text. indent1 is the start of the first line, and indent is used at the start of succeeding lines ("" is OK); indents are counted in the line width. The returned string always ends with "\n". | |
void | printArgs (G4String indent1) |
printArgs() will print (to stdout) the named arguments of the command entered, for log purposes. Calls defineNamedArgs() with argMode=PRINT to print the args. indent1 is the indent for the first line. | |
Protected Attributes | |
ArgumentMode | argMode |
bool | argFound |
G4String | argName |
G4String | argValue |
G4String | synopsis |
G4String | description |
G4String | printArgString |
int | nArgs |
int | nFixed |
int | nTunable |
BLCmdType | type |
Private Types | |
enum | TokenType { NONE, ARGNAME, ARGVALUE } |
Private Member Functions | |
void | printArgDesc (G4String name, G4String _description) |
printArgDesc will print the description of an argument, using wrapWords(). | |
Static Private Member Functions | |
static G4String | nextToken (const G4String &line, G4String::size_type &place, TokenType &type) |
nextToken() will return the next token in line; called only by doCommand(). Side-effect: updates place and sets type. | |
Static Private Attributes | |
static std::map< G4String, BLCommand * > * | mapCommand |
static int | errors = 0 |
static std::istream * | in = 0 |
Friends | |
class | BLCMDplace |
class | BLCMDhelp |
enum BLCommand::TokenType [private] |
enum BLCommand::ArgumentMode [protected] |
BLCommand::BLCommand | ( | ) | [inline, protected] |
BLCommand::BLCommand | ( | const BLCommand & | r | ) | [inline, protected] |
G4String BLCommand::nextToken | ( | const G4String & | line, | |
G4String::size_type & | place, | |||
TokenType & | type | |||
) | [static, private] |
nextToken() will return the next token in line; called only by doCommand(). Side-effect: updates place and sets type.
References ARGNAME, ARGVALUE, and NONE.
Referenced by doCommand(), and parseArgs().
00489 { 00490 // (add +- for particlecolor pi+=1,1,1) 00491 static const char namechars[] = ",+-ABCDEFGHIJKLMNOPQRSTUVWXYZ_" 00492 "abcdefghijklmnopqrstuvwxyz0123456789"; 00493 G4String::size_type i; 00494 00495 // check if previous token was ARGNAME 00496 if(line[place] == '=') { 00497 ++place; 00498 goto value; 00499 } 00500 00501 // skip initial whitespace 00502 while(place < line.size() && isspace(line[place])) ++place; 00503 00504 // check for ARGNAME 00505 if(isalnum(line[place]) || line[place] == '_') { 00506 i = line.find_first_not_of(namechars,place); 00507 if(i > place && i < line.size() && line[i] == '=' && 00508 line[i+1] != '=') { 00509 G4String retval = line.substr(place,i-place); 00510 place = i; 00511 type = ARGNAME; 00512 return retval; 00513 } 00514 } 00515 value: 00516 if(line[place] == '"') { 00517 ++place; 00518 i = line.find('"',place); 00519 if(i <line.size()) { 00520 G4String retval = line.substr(place,i-place); 00521 place = i + 1; 00522 type = ARGVALUE; 00523 return retval; 00524 } 00525 } else if(line[place] == '\'') { 00526 ++place; 00527 i = line.find('\'',place); 00528 if(i <line.size()) { 00529 G4String retval = line.substr(place,i-place); 00530 place = i + 1; 00531 type = ARGVALUE; 00532 return retval; 00533 } 00534 } 00535 00536 if(place >= line.size()) { 00537 type = NONE; 00538 return ""; 00539 } 00540 00541 // find next whitespace 00542 G4String::size_type start = place; 00543 while(place < line.size() && !isspace(line[place])) ++place; 00544 00545 type = ARGVALUE; 00546 00547 return line.substr(start,place-start); 00548 }
void BLCommand::printArgDesc | ( | G4String | name, | |
G4String | _description | |||
) | [private] |
printArgDesc will print the description of an argument, using wrapWords().
References IndentArg(), IndentDesc(), and wrapWords().
Referenced by argDouble(), argInt(), argString(), and argTunable().
00316 { 00317 G4String indent1(IndentDesc); 00318 indent1 += name; 00319 do { indent1 += " "; } while(indent1.size() < IndentArg.size()); 00320 printf("%s",wrapWords(_description,indent1,IndentArg).c_str()); 00321 }
void BLCommand::registerCommand | ( | BLCmdType | _type | ) | [protected] |
registerCommand() registers the command. Used only in the default constructor -- ensures mapCommand is properly initialized regardless of order.
References commandName(), mapCommand, printError(), and type.
Referenced by BLCMDabsorber::BLCMDabsorber(), BLCMDbeam::BLCMDbeam(), BLCMDbeamlossntuple::BLCMDbeamlossntuple(), BLCMDbox::BLCMDbox(), BLCMDbug1021::BLCMDbug1021(), BLCMDcoil::BLCMDcoil(), BLCMDcollective::BLCMDcollective(), BLCMDcorner::BLCMDcorner(), BLCMDcornerarc::BLCMDcornerarc(), BLCMDcosmicraybeam::BLCMDcosmicraybeam(), BLCMDdefine::BLCMDdefine(), BLCMDdemo::BLCMDdemo(), BLCMDdo::BLCMDdo(), BLCMDendgroup::BLCMDendgroup(), BLCMDeventcuts::BLCMDeventcuts(), BLCMDexit::BLCMDexit(), BLCMDextrusion::BLCMDextrusion(), BLCMDfieldexpr::BLCMDfieldexpr(), BLCMDfieldlines::BLCMDfieldlines(), BLCMDfieldmap::BLCMDfieldmap(), BLCMDfieldntuple::BLCMDfieldntuple(), BLCMDg4ui::BLCMDg4ui(), BLCMDgenericbend::BLCMDgenericbend(), BLCMDgenericquad::BLCMDgenericquad(), BLCMDgeometry::BLCMDgeometry(), BLCMDhelicaldipole::BLCMDhelicaldipole(), BLCMDhelicalharmonic::BLCMDhelicalharmonic(), BLCMDhelp::BLCMDhelp(), BLCMDidealsectorbend::BLCMDidealsectorbend(), BLCMDif::BLCMDif(), BLCMDinclude::BLCMDinclude(), BLCMDlist::BLCMDlist(), BLCMDmaterial::BLCMDmaterial(), BLCMDmovie::BLCMDmovie(), BLCMDmultipole::BLCMDmultipole(), BLCMDmuminuscapturefix::BLCMDmuminuscapturefix(), BLCMDnewparticlentuple::BLCMDnewparticlentuple(), BLCMDntuple::BLCMDntuple(), BLCMDoutput::BLCMDoutput(), BLCMDparam::BLCMDparam(), BLCMDparticlecolor::BLCMDparticlecolor(), BLCMDparticlefilter::BLCMDparticlefilter(), BLCMDparticlesource::BLCMDparticlesource(), BLCMDphysics::BLCMDphysics(), BLCMDpillbox::BLCMDpillbox(), BLCMDplace::BLCMDplace(), BLCMDpolycone::BLCMDpolycone(), BLCMDprintf::BLCMDprintf(), BLCMDprintfield::BLCMDprintfield(), BLCMDprobefield::BLCMDprobefield(), BLCMDprofile::BLCMDprofile(), BLCMDrandomseed::BLCMDrandomseed(), BLCMDreference::BLCMDreference(), BLCMDsetdecay::BLCMDsetdecay(), BLCMDshowmaterial::BLCMDshowmaterial(), BLCMDsolenoid::BLCMDsolenoid(), BLCMDspacecharge::BLCMDspacecharge(), BLCMDspacechargelw::BLCMDspacechargelw(), BLCMDsphere::BLCMDsphere(), BLCMDstart::BLCMDstart(), BLCMDtest::BLCMDtest(), BLCMDtimentuple::BLCMDtimentuple(), BLCMDtorus::BLCMDtorus(), BLCMDtotalenergy::BLCMDtotalenergy(), BLCMDtrace::BLCMDtrace(), BLCMDtrackcuts::BLCMDtrackcuts(), BLCMDtracker::BLCMDtracker(), BLCMDtrackermode::BLCMDtrackermode(), BLCMDtrackerplane::BLCMDtrackerplane(), BLCMDtrap::BLCMDtrap(), BLCMDtubs::BLCMDtubs(), BLCMDtune::BLCMDtune(), BLCMDusertrackfilter::BLCMDusertrackfilter(), BLCMDvirtualdetector::BLCMDvirtualdetector(), BLCMDzntuple::BLCMDzntuple(), BLCommandAlias::BLCommandAlias(), BLGroup::BLGroup(), and Macro::Macro().
00057 { 00058 type = _type; 00059 00060 if(!mapCommand) 00061 mapCommand = new std::map<G4String,BLCommand*>; 00062 if((*mapCommand).count(commandName()) > 0 && 00063 (*mapCommand)[commandName()] != this) 00064 printError("Attempt to re-define the command '%s'", 00065 commandName().c_str()); 00066 else 00067 (*mapCommand)[commandName()] = this; 00068 }
void BLCommand::deleteCommand | ( | G4String & | name | ) | [inline, protected] |
deleteCommand() will delete a command by name
References mapCommand.
Referenced by Macro::Macro().
00139 { if(mapCommand) mapCommand->erase(name); }
void BLCommand::setSynopsis | ( | const char * | _synopsis | ) | [inline, protected] |
setSynopsis() gives a 1-line (64 char) description of what the command does. Used by the help command with no arguments. The string should be 64 characters or less, and should not contain any newline; no word wrapping. Used only in the default constructor.
References synopsis.
Referenced by BLCMDabsorber::BLCMDabsorber(), BLCMDbeam::BLCMDbeam(), BLCMDbeamlossntuple::BLCMDbeamlossntuple(), BLCMDbox::BLCMDbox(), BLCMDbug1021::BLCMDbug1021(), BLCMDcoil::BLCMDcoil(), BLCMDcollective::BLCMDcollective(), BLCMDcorner::BLCMDcorner(), BLCMDcornerarc::BLCMDcornerarc(), BLCMDcosmicraybeam::BLCMDcosmicraybeam(), BLCMDdefine::BLCMDdefine(), BLCMDdemo::BLCMDdemo(), BLCMDdo::BLCMDdo(), BLCMDendgroup::BLCMDendgroup(), BLCMDeventcuts::BLCMDeventcuts(), BLCMDexit::BLCMDexit(), BLCMDextrusion::BLCMDextrusion(), BLCMDfieldexpr::BLCMDfieldexpr(), BLCMDfieldlines::BLCMDfieldlines(), BLCMDfieldmap::BLCMDfieldmap(), BLCMDfieldntuple::BLCMDfieldntuple(), BLCMDg4ui::BLCMDg4ui(), BLCMDgenericbend::BLCMDgenericbend(), BLCMDgenericquad::BLCMDgenericquad(), BLCMDgeometry::BLCMDgeometry(), BLCMDhelicaldipole::BLCMDhelicaldipole(), BLCMDhelicalharmonic::BLCMDhelicalharmonic(), BLCMDhelp::BLCMDhelp(), BLCMDidealsectorbend::BLCMDidealsectorbend(), BLCMDif::BLCMDif(), BLCMDinclude::BLCMDinclude(), BLCMDlist::BLCMDlist(), BLCMDmaterial::BLCMDmaterial(), BLCMDmovie::BLCMDmovie(), BLCMDmultipole::BLCMDmultipole(), BLCMDmuminuscapturefix::BLCMDmuminuscapturefix(), BLCMDnewparticlentuple::BLCMDnewparticlentuple(), BLCMDntuple::BLCMDntuple(), BLCMDoutput::BLCMDoutput(), BLCMDparam::BLCMDparam(), BLCMDparticlecolor::BLCMDparticlecolor(), BLCMDparticlefilter::BLCMDparticlefilter(), BLCMDparticlesource::BLCMDparticlesource(), BLCMDphysics::BLCMDphysics(), BLCMDpillbox::BLCMDpillbox(), BLCMDplace::BLCMDplace(), BLCMDpolycone::BLCMDpolycone(), BLCMDprintf::BLCMDprintf(), BLCMDprintfield::BLCMDprintfield(), BLCMDprobefield::BLCMDprobefield(), BLCMDprofile::BLCMDprofile(), BLCMDrandomseed::BLCMDrandomseed(), BLCMDreference::BLCMDreference(), BLCMDsetdecay::BLCMDsetdecay(), BLCMDshowmaterial::BLCMDshowmaterial(), BLCMDsolenoid::BLCMDsolenoid(), BLCMDspacecharge::BLCMDspacecharge(), BLCMDspacechargelw::BLCMDspacechargelw(), BLCMDsphere::BLCMDsphere(), BLCMDstart::BLCMDstart(), BLCMDtest::BLCMDtest(), BLCMDtimentuple::BLCMDtimentuple(), BLCMDtorus::BLCMDtorus(), BLCMDtotalenergy::BLCMDtotalenergy(), BLCMDtrace::BLCMDtrace(), BLCMDtrackcuts::BLCMDtrackcuts(), BLCMDtracker::BLCMDtracker(), BLCMDtrackermode::BLCMDtrackermode(), BLCMDtrackerplane::BLCMDtrackerplane(), BLCMDtrap::BLCMDtrap(), BLCMDtubs::BLCMDtubs(), BLCMDtune::BLCMDtune(), BLCMDusertrackfilter::BLCMDusertrackfilter(), BLCMDvirtualdetector::BLCMDvirtualdetector(), BLCMDzntuple::BLCMDzntuple(), BLCommandAlias::BLCommandAlias(), BLGroup::BLGroup(), and Macro::Macro().
00147 { synopsis = _synopsis; }
void BLCommand::setDescription | ( | const char * | _description | ) | [inline, protected] |
setDescription() gives a more complete description of the command, when help for this specific command is requested. When printed by the help() function, word wrapping is performed, but lines beginning with whitespace are kept intact. Named arguments are automatically described by the help() function, but positional arguments should be described here. Words are wrapped using wrapWords(). Used only in the default constructor.
References description.
Referenced by BLCMDabsorber::BLCMDabsorber(), BLCMDbeam::BLCMDbeam(), BLCMDbeamlossntuple::BLCMDbeamlossntuple(), BLCMDbox::BLCMDbox(), BLCMDbug1021::BLCMDbug1021(), BLCMDcoil::BLCMDcoil(), BLCMDcollective::BLCMDcollective(), BLCMDcorner::BLCMDcorner(), BLCMDcornerarc::BLCMDcornerarc(), BLCMDcosmicraybeam::BLCMDcosmicraybeam(), BLCMDdefine::BLCMDdefine(), BLCMDdemo::BLCMDdemo(), BLCMDdo::BLCMDdo(), BLCMDendgroup::BLCMDendgroup(), BLCMDeventcuts::BLCMDeventcuts(), BLCMDexit::BLCMDexit(), BLCMDextrusion::BLCMDextrusion(), BLCMDfieldexpr::BLCMDfieldexpr(), BLCMDfieldlines::BLCMDfieldlines(), BLCMDfieldmap::BLCMDfieldmap(), BLCMDfieldntuple::BLCMDfieldntuple(), BLCMDg4ui::BLCMDg4ui(), BLCMDgenericbend::BLCMDgenericbend(), BLCMDgenericquad::BLCMDgenericquad(), BLCMDgeometry::BLCMDgeometry(), BLCMDhelicaldipole::BLCMDhelicaldipole(), BLCMDhelicalharmonic::BLCMDhelicalharmonic(), BLCMDhelp::BLCMDhelp(), BLCMDidealsectorbend::BLCMDidealsectorbend(), BLCMDif::BLCMDif(), BLCMDinclude::BLCMDinclude(), BLCMDlist::BLCMDlist(), BLCMDmaterial::BLCMDmaterial(), BLCMDmovie::BLCMDmovie(), BLCMDmultipole::BLCMDmultipole(), BLCMDmuminuscapturefix::BLCMDmuminuscapturefix(), BLCMDnewparticlentuple::BLCMDnewparticlentuple(), BLCMDntuple::BLCMDntuple(), BLCMDoutput::BLCMDoutput(), BLCMDparam::BLCMDparam(), BLCMDparticlecolor::BLCMDparticlecolor(), BLCMDparticlefilter::BLCMDparticlefilter(), BLCMDparticlesource::BLCMDparticlesource(), BLCMDphysics::BLCMDphysics(), BLCMDpillbox::BLCMDpillbox(), BLCMDplace::BLCMDplace(), BLCMDpolycone::BLCMDpolycone(), BLCMDprintf::BLCMDprintf(), BLCMDprintfield::BLCMDprintfield(), BLCMDprobefield::BLCMDprobefield(), BLCMDprofile::BLCMDprofile(), BLCMDrandomseed::BLCMDrandomseed(), BLCMDreference::BLCMDreference(), BLCMDsetdecay::BLCMDsetdecay(), BLCMDshowmaterial::BLCMDshowmaterial(), BLCMDsolenoid::BLCMDsolenoid(), BLCMDspacecharge::BLCMDspacecharge(), BLCMDspacechargelw::BLCMDspacechargelw(), BLCMDsphere::BLCMDsphere(), BLCMDstart::BLCMDstart(), BLCMDtest::BLCMDtest(), BLCMDtimentuple::BLCMDtimentuple(), BLCMDtorus::BLCMDtorus(), BLCMDtotalenergy::BLCMDtotalenergy(), BLCMDtrace::BLCMDtrace(), BLCMDtrackcuts::BLCMDtrackcuts(), BLCMDtracker::BLCMDtracker(), BLCMDtrackermode::BLCMDtrackermode(), BLCMDtrackerplane::BLCMDtrackerplane(), BLCMDtrap::BLCMDtrap(), BLCMDtubs::BLCMDtubs(), BLCMDtune::BLCMDtune(), BLCMDusertrackfilter::BLCMDusertrackfilter(), BLCMDvirtualdetector::BLCMDvirtualdetector(), BLCMDzntuple::BLCMDzntuple(), BLCommandAlias::BLCommandAlias(), and BLGroup::BLGroup().
00158 { description = _description; }
void BLCommand::argString | ( | G4String & | var, | |
G4String | name, | |||
G4String | description, | |||
bool | permitChange = true | |||
) | [protected] |
argString() declares a string-valued argument. name should be a valid C identifier 15 chars or less, and description should be a short description (wrapWords() is used). Used only in the defineNamedArgs() function. permitChange affects whether this argument can be set when an element is placed.
References argFound, argMode, argName, argValue, CHANGE, commandName(), COUNT, HELP, nArgs, nFixed, PRINT, printArgDesc(), printArgString, printError(), and PROCESS.
Referenced by BLCMDzntuple::defineNamedArgs(), BLCMDvirtualdetector::defineNamedArgs(), BLCMDusertrackfilter::defineNamedArgs(), BLCMDtune::defineNamedArgs(), BLCMDtubs::defineNamedArgs(), BLCMDtrap::defineNamedArgs(), BLCMDtrackermode::defineNamedArgs(), BLCMDtrackerplane::defineNamedArgs(), BLCMDtracker::defineNamedArgs(), BLCMDtrackcuts::defineNamedArgs(), BLCMDtrace::defineNamedArgs(), BLCMDtotalenergy::defineNamedArgs(), BLCMDtorus::defineNamedArgs(), BLCMDtimentuple::defineNamedArgs(), BLCMDstart::defineNamedArgs(), BLCMDsphere::defineNamedArgs(), BLCMDsolenoid::defineNamedArgs(), BLCMDreference::defineNamedArgs(), BLCMDprofile::defineNamedArgs(), BLCMDprobefield::defineNamedArgs(), BLCMDprintfield::defineNamedArgs(), BLCMDprintf::defineNamedArgs(), BLCMDpolycone::defineNamedArgs(), BLCMDplace::defineNamedArgs(), BLCMDpillbox::defineNamedArgs(), BLCMDphysics::defineNamedArgs(), BLCMDparticlefilter::defineNamedArgs(), BLCMDntuple::defineNamedArgs(), BLCMDnewparticlentuple::defineNamedArgs(), BLCMDmultipole::defineNamedArgs(), BLCMDmovie::defineNamedArgs(), BLCMDmaterial::defineNamedArgs(), BLCMDlist::defineNamedArgs(), BLCMDidealsectorbend::defineNamedArgs(), BLGroup::defineNamedArgs(), BLCMDgenericquad::defineNamedArgs(), BLCMDgenericbend::defineNamedArgs(), BLCMDfieldntuple::defineNamedArgs(), BLCMDfieldmap::defineNamedArgs(), BLCMDfieldlines::defineNamedArgs(), BLCMDfieldexpr::defineNamedArgs(), BLCMDextrusion::defineNamedArgs(), BLCMDeventcuts::defineNamedArgs(), BLCMDdemo::defineNamedArgs(), BLCMDcornerarc::defineNamedArgs(), BLCMDcorner::defineNamedArgs(), BLCMDcollective::defineNamedArgs(), BLCMDcoil::defineNamedArgs(), BLCMDbox::defineNamedArgs(), BLCMDbeamlossntuple::defineNamedArgs(), BLCMDbeam::defineNamedArgs(), and BLCMDabsorber::defineNamedArgs().
00134 { 00135 switch(argMode) { 00136 case CHANGE: 00137 if(!permitChange) { 00138 if(argName == name) 00139 printError("%s: Argument '%s' is not permitted to change\n", 00140 commandName().c_str(),name.c_str()); 00141 break; 00142 } 00143 // flow into PROCESS 00144 case PROCESS: 00145 if(argFound || argName != name) return; 00146 argFound = true; 00147 var = argValue; 00148 break; 00149 case COUNT: 00150 ++nArgs; 00151 if(!permitChange) ++nFixed; 00152 break; 00153 case HELP: 00154 printArgDesc(name,_description+(permitChange?"":" #")); 00155 break; 00156 case PRINT: 00157 printArgString += name; 00158 printArgString += "="; 00159 printArgString += var; 00160 printArgString += "\n"; 00161 break; 00162 } 00163 }
void BLCommand::argDouble | ( | G4double & | var, | |
G4String | name, | |||
G4String | description, | |||
G4double | units = 1.0 , |
|||
G4String | fmt = DefaultDoubleFmt , |
|||
bool | permitChange = true | |||
) | [protected] |
argDouble() declares a G4double-valued argument. name should be a valid C identifier 15 chars or less, and description should be a short description (wrapWords() is used). Used only in the defineNamedArgs() function. units should be the human units for the argument, because the value of var is always in internal units. fmt and units are used when argMode=PRINT. permitChange affects whether this argument can be set when an element is placed.
References argFound, argMode, argName, argValue, CHANGE, commandName(), COUNT, DefaultDoubleFmt, BLEvaluator::evaluate(), HELP, nArgs, nFixed, PRINT, printArgDesc(), printArgString, printError(), PROCESS, and snprintf.
Referenced by BLCMDvirtualdetector::defineNamedArgs(), BLCMDusertrackfilter::defineNamedArgs(), BLCMDtune::defineNamedArgs(), BLCMDtubs::defineNamedArgs(), BLCMDtrap::defineNamedArgs(), BLCMDtrackerplane::defineNamedArgs(), BLCMDtracker::defineNamedArgs(), BLCMDtrackcuts::defineNamedArgs(), BLCMDtorus::defineNamedArgs(), BLCMDtimentuple::defineNamedArgs(), BLCMDstart::defineNamedArgs(), BLCMDsphere::defineNamedArgs(), BLCMDspacechargelw::defineNamedArgs(), BLCMDspacecharge::defineNamedArgs(), BLCMDsolenoid::defineNamedArgs(), BLCMDreference::defineNamedArgs(), BLCMDprintfield::defineNamedArgs(), BLCMDprintf::defineNamedArgs(), BLCMDpolycone::defineNamedArgs(), BLCMDplace::defineNamedArgs(), BLCMDpillbox::defineNamedArgs(), BLCMDphysics::defineNamedArgs(), BLCMDparticlefilter::defineNamedArgs(), BLCMDmuminuscapturefix::defineNamedArgs(), BLCMDmultipole::defineNamedArgs(), BLCMDmaterial::defineNamedArgs(), BLCMDidealsectorbend::defineNamedArgs(), BLCMDhelicalharmonic::defineNamedArgs(), BLCMDhelicaldipole::defineNamedArgs(), BLGroup::defineNamedArgs(), BLCMDgeometry::defineNamedArgs(), BLCMDgenericquad::defineNamedArgs(), BLCMDgenericbend::defineNamedArgs(), BLCMDfieldmap::defineNamedArgs(), BLCMDfieldlines::defineNamedArgs(), BLCMDfieldexpr::defineNamedArgs(), BLCMDextrusion::defineNamedArgs(), BLCMDdemo::defineNamedArgs(), BLCMDcosmicraybeam::defineNamedArgs(), BLCMDcornerarc::defineNamedArgs(), BLCMDcorner::defineNamedArgs(), BLCMDcollective::defineNamedArgs(), BLCMDcoil::defineNamedArgs(), BLCMDbug1021::defineNamedArgs(), BLCMDbox::defineNamedArgs(), BLCMDbeam::defineNamedArgs(), and BLCMDabsorber::defineNamedArgs().
00167 { 00168 if(fmt == "") fmt = DefaultDoubleFmt; 00169 00170 switch(argMode) { 00171 case CHANGE: 00172 if(!permitChange) { 00173 if(argName == name) 00174 printError("%s: Argument '%s' is not permitted to change\n", 00175 commandName().c_str(),name.c_str()); 00176 break; 00177 } 00178 // flow into PROCESS 00179 case PROCESS: 00180 if(argFound || argName != name) return; 00181 argFound = true; 00182 { BLEvaluator e; 00183 G4double v = e.evaluate(argValue); 00184 if(e.status() != HepTool::Evaluator::OK) { 00185 printError("Invalid value for argument '%s'" 00186 " to command '%s'", argName.c_str(), 00187 commandName().c_str()); 00188 return; 00189 } 00190 var = v * units; 00191 } 00192 /**** 00193 { const char *p=argValue.c_str(); 00194 char *q; 00195 G4double v = strtod(p,&q); 00196 if(p == q || *q != '\0') { 00197 printError("Invalid value for argument '%s'" 00198 " to command '%s'", argName.c_str(), 00199 commandName().c_str()); 00200 return; 00201 } 00202 var = v * units; 00203 } 00204 ****/ 00205 break; 00206 case COUNT: 00207 ++nArgs; 00208 if(!permitChange) ++nFixed; 00209 break; 00210 case HELP: 00211 printArgDesc(name,_description+(permitChange?"":" #")); 00212 break; 00213 case PRINT: 00214 { char tmp[65]; 00215 snprintf(tmp,sizeof(tmp),fmt.c_str(),var/units); 00216 printArgString += name; 00217 printArgString += "="; 00218 printArgString += tmp; 00219 printArgString += "\n"; 00220 } 00221 break; 00222 } 00223 }
void BLCommand::argTunable | ( | G4double & | var, | |
G4String | name, | |||
G4String | description, | |||
G4double | units = 1.0 , |
|||
G4String | fmt = DefaultDoubleFmt | |||
) | [protected] |
argTunable() declares a G4double-valued argument that is tunable (see the tune command in BLCMDtune.cc). name should be a valid C identifier 15 chars or less, and description should be a short description (wrapWords() is used). Used only in the defineNamedArgs() function. units should be the human units for the argument, because the value of var is always in internal units. fmt and units are used when argMode=PRINT. Tunable arguments can always be set when an element is placed, and will be changed during the tracking of the Tune Particle if their value includes a tune variable. See BLTune.hh for a description of how tunable arguments are handled.
References argFound, argMode, argName, argValue, CHANGE, COUNT, DefaultDoubleFmt, BLTune::defineTunableArg(), HELP, nArgs, nTunable, PRINT, printArgDesc(), printArgString, PROCESS, and snprintf.
Referenced by BLCMDpillbox::defineNamedArgs(), BLCMDidealsectorbend::defineNamedArgs(), BLCMDgenericbend::defineNamedArgs(), BLCMDfieldmap::defineNamedArgs(), and BLCMDfieldexpr::defineNamedArgs().
00227 { 00228 if(fmt == "") fmt = DefaultDoubleFmt; 00229 00230 switch(argMode) { 00231 case CHANGE: 00232 case PROCESS: 00233 if(argFound || argName != name) return; 00234 argFound = true; 00235 BLTune::defineTunableArg(var,units,argValue); 00236 break; 00237 case HELP: 00238 printArgDesc(name,_description+" @"); 00239 break; 00240 case COUNT: 00241 ++nArgs; 00242 ++nTunable; 00243 break; 00244 case PRINT: 00245 { char tmp[65]; 00246 snprintf(tmp,sizeof(tmp),fmt.c_str(),var/units); 00247 printArgString += name; 00248 printArgString += "="; 00249 printArgString += tmp; 00250 printArgString += "\n"; 00251 } 00252 break; 00253 } 00254 }
void BLCommand::argInt | ( | G4int & | var, | |
G4String | name, | |||
G4String | description, | |||
bool | permitChange = true | |||
) | [protected] |
argInt() declares a integer-valued argument. name should be a valid C identifier 15 chars or less, and description should be a short description (wrapWords() is used). Used only in the defineNamedArgs() function. permitChange affects whether this argument can be set when an element is placed.
References argFound, argMode, argName, argValue, CHANGE, commandName(), COUNT, BLEvaluator::evaluate(), HELP, nArgs, nFixed, PRINT, printArgDesc(), printArgString, printError(), PROCESS, and snprintf.
Referenced by BLCMDzntuple::defineNamedArgs(), BLCMDvirtualdetector::defineNamedArgs(), BLCMDtune::defineNamedArgs(), BLCMDtubs::defineNamedArgs(), BLCMDtrap::defineNamedArgs(), BLCMDtracker::defineNamedArgs(), BLCMDtrackcuts::defineNamedArgs(), BLCMDtrace::defineNamedArgs(), BLCMDtotalenergy::defineNamedArgs(), BLCMDtorus::defineNamedArgs(), BLCMDstart::defineNamedArgs(), BLCMDsphere::defineNamedArgs(), BLCMDspacechargelw::defineNamedArgs(), BLCMDspacecharge::defineNamedArgs(), BLCMDsolenoid::defineNamedArgs(), BLCMDreference::defineNamedArgs(), BLCMDprintfield::defineNamedArgs(), BLCMDpolycone::defineNamedArgs(), BLCMDplace::defineNamedArgs(), BLCMDpillbox::defineNamedArgs(), BLCMDphysics::defineNamedArgs(), BLCMDparticlesource::defineNamedArgs(), BLCMDparticlefilter::defineNamedArgs(), BLCMDntuple::defineNamedArgs(), BLCMDmultipole::defineNamedArgs(), BLCMDidealsectorbend::defineNamedArgs(), BLCMDhelicalharmonic::defineNamedArgs(), BLCMDgeometry::defineNamedArgs(), BLCMDgenericquad::defineNamedArgs(), BLCMDgenericbend::defineNamedArgs(), BLCMDg4ui::defineNamedArgs(), BLCMDfieldntuple::defineNamedArgs(), BLCMDfieldlines::defineNamedArgs(), BLCMDfieldexpr::defineNamedArgs(), BLCMDextrusion::defineNamedArgs(), BLCMDcosmicraybeam::defineNamedArgs(), BLCMDcoil::defineNamedArgs(), BLCMDbox::defineNamedArgs(), and BLCMDbeam::defineNamedArgs().
00258 { 00259 switch(argMode) { 00260 case CHANGE: 00261 if(!permitChange) { 00262 if(argName == name) 00263 printError("%s: Argument '%s' is not permitted to change\n", 00264 commandName().c_str(),name.c_str()); 00265 break; 00266 } 00267 // flow into PROCESS 00268 case PROCESS: 00269 if(argFound || argName != name) return; 00270 argFound = true; 00271 { BLEvaluator e; 00272 G4double v = e.evaluate(argValue); 00273 var = (G4int)(v+0.5); 00274 if(e.status() != HepTool::Evaluator::OK || 00275 fabs(var-v) > 0.001) { 00276 printError("Invalid value for argument '%s'" 00277 " to command '%s'", argName.c_str(), 00278 commandName().c_str()); 00279 return; 00280 } 00281 } 00282 /*** 00283 { const char *p=argValue.c_str(); 00284 char *q; 00285 G4int v = strtol(p,&q,0); 00286 if(p == q || *q != '\0') { 00287 printError("Invalid value for argument '%s'" 00288 " to command '%s'", argName.c_str(), 00289 commandName().c_str()); 00290 return; 00291 } 00292 var = v; 00293 } 00294 ***/ 00295 break; 00296 case COUNT: 00297 ++nArgs; 00298 if(!permitChange) ++nFixed; 00299 break; 00300 case HELP: 00301 printArgDesc(name,_description+(permitChange?"":" #")); 00302 break; 00303 case PRINT: 00304 { char tmp[65]; 00305 snprintf(tmp,sizeof(tmp),"%d",var); 00306 printArgString += name; 00307 printArgString += "="; 00308 printArgString += tmp; 00309 printArgString += "\n"; 00310 } 00311 break; 00312 } 00313 }
int BLCommand::handleNamedArgs | ( | BLArgumentMap & | namedArgs | ) | [protected] |
handleNamedArgs() handles all named arguments to the command (i.e. those defined in defineNamedArgs()). For use in the command() function. returns 0 if OK, -1 on error.
Reimplemented in BLCMDplace.
References argChanged(), argFound, argMode, argName, argValue, commandName(), defineNamedArgs(), printError(), and PROCESS.
Referenced by BLCMDzntuple::command(), BLCMDvirtualdetector::command(), BLCMDusertrackfilter::command(), BLCMDtune::command(), BLCMDtubs::command(), BLCMDtrap::command(), BLCMDtrackermode::command(), BLCMDtrackerplane::command(), BLCMDtracker::command(), BLCMDtrackcuts::command(), BLCMDtrace::command(), BLCMDtotalenergy::command(), BLCMDtorus::command(), BLCMDtimentuple::command(), BLCMDstart::command(), BLCMDsphere::command(), BLCMDspacechargelw::command(), BLCMDspacecharge::command(), BLCMDsolenoid::command(), BLCMDreference::command(), BLCMDprofile::command(), BLCMDprobefield::command(), BLCMDprintfield::command(), BLCMDprintf::command(), BLCMDpolycone::command(), BLCMDpillbox::command(), BLCMDphysics::command(), BLCMDparticlesource::command(), BLCMDparticlefilter::command(), BLCMDntuple::command(), BLCMDnewparticlentuple::command(), BLCMDmuminuscapturefix::command(), BLCMDmultipole::command(), BLCMDmovie::command(), BLCMDmaterial::command(), BLCMDlist::command(), BLCMDidealsectorbend::command(), BLCMDhelicalharmonic::command(), BLCMDhelicaldipole::command(), BLGroup::command(), BLCMDgeometry::command(), BLCMDgenericquad::command(), BLCMDgenericbend::command(), BLCMDg4ui::command(), BLCMDfieldntuple::command(), BLCMDfieldmap::command(), BLCMDfieldlines::command(), BLCMDfieldexpr::command(), BLCMDextrusion::command(), BLCMDeventcuts::command(), BLCMDdemo::command(), BLCMDcosmicraybeam::command(), BLCMDcornerarc::command(), BLCMDcorner::command(), BLCMDcollective::command(), BLCMDcoil::command(), BLCMDbug1021::command(), BLCMDbox::command(), BLCMDbeamlossntuple::command(), BLCMDbeam::command(), and BLCMDabsorber::command().
00324 { 00325 int retval = 0; 00326 argMode = PROCESS; 00327 00328 BLArgumentMap::iterator i; 00329 for(i=args.begin(); i!=args.end(); ++i) { 00330 argName = i->first; 00331 argValue = i->second; 00332 argFound = false; 00333 defineNamedArgs(); 00334 if(!argFound) { 00335 printError("Invalid argument '%s' to command '%s'", 00336 argName.c_str(),commandName().c_str()); 00337 retval = -1; 00338 } 00339 } 00340 00341 if(args.size() > 0) argChanged(); 00342 00343 return retval; 00344 }
void BLCommand::help | ( | bool | detailed | ) | [protected, virtual] |
help() prints the help information for this command. detailed=false prints only the name and synopsis; true prints the description and arguments also.
Reimplemented in BLCMDbeamlossntuple, BLCMDmaterial, BLCMDnewparticlentuple, BLCMDparam, BLCMDphysics, BLCMDtimentuple, BLCMDtrace, BLCMDvirtualdetector, and BLCMDzntuple.
References argMode, commandName(), COUNT, defineNamedArgs(), description, BLNTuple::getFormatList(), HELP, IndentDesc(), nArgs, nFixed, nTunable, synopsis, and wrapWords().
Referenced by BLCMDzntuple::help(), BLCMDvirtualdetector::help(), BLCMDtrace::help(), BLCMDtimentuple::help(), BLCMDphysics::help(), BLCMDparam::help(), BLCMDnewparticlentuple::help(), BLCMDmaterial::help(), and BLCMDbeamlossntuple::help().
00352 { 00353 G4String str(commandName()); 00354 do { str += " "; } while(str.size() < IndentDesc.size()); 00355 printf("%s%s\n",str.c_str(),synopsis.c_str()); 00356 if(detailed) { 00357 if(description.rfind(": ") == description.size()-2) 00358 description += BLNTuple::getFormatList(); 00359 printf("\n%s",wrapWords(description,IndentDesc,IndentDesc).c_str()); 00360 nArgs = nFixed = nTunable = 0; 00361 argMode = COUNT; 00362 defineNamedArgs(); 00363 if(nArgs > 0) { 00364 printf("\n%sNamed Arguments", IndentDesc.c_str()); 00365 if(nFixed > 0) 00366 printf(" (#=cannot be changed in place cmd)"); 00367 if(nTunable > 0) printf(" (@=Tunable)"); 00368 printf(":\n"); 00369 argMode = HELP; 00370 defineNamedArgs(); 00371 } 00372 } 00373 }
G4String BLCommand::wrapWords | ( | G4String | text, | |
G4String | indent1, | |||
G4String | indent, | |||
G4String::size_type | width = 79 | |||
) | [protected] |
wrapWords() will wrap words for descriptions in help(). In text, lines beginning with whitespace are preserved as is, including blank lines. Otherwise, newlines aren't needed in text. indent1 is the start of the first line, and indent is used at the start of succeeding lines ("" is OK); indents are counted in the line width. The returned string always ends with "\n".
Referenced by help(), BLCMDlist::listParticleDetails(), print(), printArgDesc(), printArgs(), and BLCMDphysics::printCase().
00082 { 00083 G4String retval(""), space(" "), line(""), word(""); 00084 G4String::size_type pos=0, next=0; 00085 bool eol=false; 00086 00087 while(pos < text.size()) { 00088 if(eol && isspace(text[pos])) { 00089 next = text.find_first_of("\n",pos); 00090 if(next == text.npos) next = text.size(); 00091 if(line.size() > 0) {retval += line; retval += "\n";} 00092 line = indent + text.substr(pos,next-pos); 00093 retval += line; 00094 retval += "\n"; 00095 line = ""; 00096 pos = next + 1; 00097 // eol = true; 00098 continue; 00099 } 00100 next = text.find_first_of(" \t\r\n",pos); 00101 if(next == text.npos) { 00102 word = text.substr(pos); 00103 next = text.size(); 00104 } else { 00105 word = text.substr(pos,next-pos); 00106 eol = (text[next] == '\n'); 00107 } 00108 if(word.size() > 0) { 00109 if(line.size() == 0) { 00110 if(retval.size() == 0) 00111 line = indent1; 00112 else 00113 line = indent; 00114 line += word; 00115 } else if(line.size()+word.size()+1 < width) { 00116 line += space; 00117 line += word; 00118 } else { 00119 retval += line; 00120 retval += "\n"; 00121 line = indent; 00122 line += word; 00123 } 00124 } 00125 pos = next + 1; 00126 } 00127 if(line.size() > 0) {retval += line; retval += "\n";} 00128 00129 return retval; 00130 }
void BLCommand::printArgs | ( | G4String | indent1 | ) | [protected] |
printArgs() will print (to stdout) the named arguments of the command entered, for log purposes. Calls defineNamedArgs() with argMode=PRINT to print the args. indent1 is the indent for the first line.
References argMode, defineNamedArgs(), IndentArg(), PRINT, printArgString, and wrapWords().
Referenced by print().
00376 { 00377 printArgString = ""; 00378 argMode = PRINT; 00379 defineNamedArgs(); 00380 printf("%s",wrapWords(printArgString,indent1,IndentArg).c_str()); 00381 }
virtual G4String BLCommand::commandName | ( | ) | [pure virtual] |
commandName() returns the name of the command.
Implemented in BLCommandAlias, BLGroup, BLCMDabsorber, BLCMDbeam, BLCMDbeamlossntuple, BLCMDbox, BLCMDbug1021, BLCMDcoil, BLCMDcollective, BLCMDcorner, BLCMDcornerarc, BLCMDcosmicraybeam, BLCMDdefine, Macro, BLCMDdemo, BLCMDdo, BLCMDendgroup, BLCMDeventcuts, BLCMDexit, BLCMDextrusion, BLCMDfieldexpr, BLCMDfieldlines, BLCMDfieldmap, BLCMDfieldntuple, BLCMDg4ui, BLCMDgenericbend, BLCMDgenericquad, BLCMDgeometry, BLCMDhelicaldipole, BLCMDhelicalharmonic, BLCMDhelp, BLCMDidealsectorbend, BLCMDif, BLCMDinclude, BLCMDlist, BLCMDmaterial, BLCMDmovie, BLCMDmultipole, BLCMDmuminuscapturefix, BLCMDnewparticlentuple, BLCMDntuple, BLCMDoutput, BLCMDparam, BLCMDparticlecolor, BLCMDparticlefilter, BLCMDparticlesource, BLCMDphysics, BLCMDpillbox, BLCMDplace, BLCMDpolycone, BLCMDprintf, BLCMDprintfield, BLCMDprobefield, BLCMDprofile, BLCMDrandomseed, BLCMDreference, BLCMDsetdecay, BLCMDshowmaterial, BLCMDsolenoid, BLCMDspacecharge, BLCMDspacechargelw, BLCMDsphere, BLCMDstart, BLCMDtest, BLCMDtimentuple, BLCMDtorus, BLCMDtotalenergy, BLCMDtrace, BLCMDtrackcuts, BLCMDtracker, BLCMDtrackerplane, BLCMDtrackermode, BLCMDtrap, BLCMDtubs, BLCMDtune, BLCMDusertrackfilter, BLCMDvirtualdetector, and BLCMDzntuple.
Referenced by argDouble(), argInt(), argString(), BLCommandAlias::BLCommandAlias(), handleNamedArgs(), help(), print(), registerCommand(), and BLGroupElement::testGeometry().
virtual int BLCommand::command | ( | BLArgumentVector & | argv, | |
BLArgumentMap & | namedArgs | |||
) | [pure virtual] |
command() executes the command associated with this element. argv and namedArgs come from parsing the command-line: argv has a vector of any positional arguments (without "="); namedArgs has a map of any named arguments of the form name=value. Returns 0 if OK, -1 on error. NOTE: for classes derived via BLElement.hh, arguments can be given when an object is defined and when it is placed. For that to work, argument values must not be used in the command() function unless they are defined with permitChange=false (in the above argString... functions). Also the correct units must be given to argDouble().
Implemented in BLCommandAlias, BLGroup, BLCMDabsorber, BLCMDbeam, BLCMDbeamlossntuple, BLCMDbox, BLCMDbug1021, BLCMDcoil, BLCMDcollective, BLCMDcorner, BLCMDcornerarc, BLCMDcosmicraybeam, BLCMDdefine, Macro, BLCMDdemo, BLCMDdo, BLCMDendgroup, BLCMDeventcuts, BLCMDexit, BLCMDextrusion, BLCMDfieldexpr, BLCMDfieldlines, BLCMDfieldmap, BLCMDfieldntuple, BLCMDg4ui, BLCMDgenericbend, BLCMDgenericquad, BLCMDgeometry, BLCMDhelicaldipole, BLCMDhelicalharmonic, BLCMDhelp, BLCMDidealsectorbend, BLCMDif, BLCMDinclude, BLCMDlist, BLCMDmaterial, BLCMDmovie, BLCMDmultipole, BLCMDmuminuscapturefix, BLCMDnewparticlentuple, BLCMDntuple, BLCMDoutput, BLCMDparam, BLCMDparticlecolor, BLCMDparticlefilter, BLCMDparticlesource, BLCMDphysics, BLCMDpillbox, BLCMDplace, BLCMDpolycone, BLCMDprintf, BLCMDprintfield, BLCMDprobefield, BLCMDprofile, BLCMDrandomseed, BLCMDreference, BLCMDsetdecay, BLCMDshowmaterial, BLCMDsolenoid, BLCMDspacecharge, BLCMDspacechargelw, BLCMDsphere, BLCMDstart, BLCMDtest, BLCMDtimentuple, BLCMDtorus, BLCMDtotalenergy, BLCMDtrace, BLCMDtrackcuts, BLCMDtracker, BLCMDtrackerplane, BLCMDtrackermode, BLCMDtrap, BLCMDtubs, BLCMDtune, BLCMDusertrackfilter, BLCMDvirtualdetector, and BLCMDzntuple.
Referenced by BLCommandAlias::command().
void BLCommand::defineNamedArgs | ( | ) | [virtual] |
defineNamedArgs() defines the named arguments for the command. This function should consist ONLY of a series of calls to argString(), argDouble(), and argInt(). Used by handleNamedArgs(), help(), and print() (they manipulate the behavior of the argXXX() functions via argMode).
Reimplemented in BLGroup, BLCMDabsorber, BLCMDbeam, BLCMDbeamlossntuple, BLCMDbox, BLCMDbug1021, BLCMDcoil, BLCMDcollective, BLCMDcorner, BLCMDcornerarc, BLCMDcosmicraybeam, Macro, BLCMDdemo, BLCMDeventcuts, BLCMDextrusion, BLCMDfieldexpr, BLCMDfieldlines, BLCMDfieldmap, BLCMDfieldntuple, BLCMDg4ui, BLCMDgenericbend, BLCMDgenericquad, BLCMDgeometry, BLCMDhelicaldipole, BLCMDhelicalharmonic, BLCMDidealsectorbend, BLCMDlist, BLCMDmaterial, BLCMDmovie, BLCMDmultipole, BLCMDmuminuscapturefix, BLCMDnewparticlentuple, BLCMDntuple, BLCMDparticlecolor, BLCMDparticlefilter, BLCMDparticlesource, BLCMDphysics, BLCMDpillbox, BLCMDplace, BLCMDpolycone, BLCMDprintf, BLCMDprintfield, BLCMDprobefield, BLCMDprofile, BLCMDrandomseed, BLCMDreference, BLCMDsetdecay, BLCMDsolenoid, BLCMDspacecharge, BLCMDspacechargelw, BLCMDsphere, BLCMDstart, BLCMDtest, BLCMDtimentuple, BLCMDtorus, BLCMDtotalenergy, BLCMDtrace, BLCMDtrackcuts, BLCMDtracker, BLCMDtrackerplane, BLCMDtrackermode, BLCMDtrap, BLCMDtubs, BLCMDtune, BLCMDusertrackfilter, BLCMDvirtualdetector, and BLCMDzntuple.
References argMode, HELP, and IndentDesc().
Referenced by handleNamedArgs(), BLCMDplace::handleNamedArgs(), help(), and printArgs().
00347 { 00348 if(argMode == HELP) printf("%s(none)\n",IndentDesc.c_str()); 00349 }
virtual void BLCommand::argChanged | ( | ) | [inline, virtual] |
argChanged() will be called whenever some argument value has changed. Derived classes should define it and perform any internal computations that depend on argument values. Many/most derived classes won't need to use it. In particular, after argChanged() returns the functions getHeight(), getWidth() and getLength() must return the correct values for the current arguments. BEWARE: a single argument change may call this multiple times. Applies only to named arguments, not positional ones.
Reimplemented in BLCMDpillbox, BLCMDtrackerplane, and BLCMDvirtualdetector.
Referenced by handleNamedArgs(), and BLCMDplace::handleNamedArgs().
void BLCommand::print | ( | G4String | name | ) | [virtual] |
print() will print to stdout the command. The default versions will do for most commands and elements. name can be "". prints commandname() and name in the space of IndentArg, followed by the values of all named arguments, in the order they appear in defineNamedArgs().
References commandName(), IndentArg(), IndentDesc(), and printArgs().
Referenced by BLCMDzntuple::command(), BLCMDvirtualdetector::command(), BLCMDusertrackfilter::command(), BLCMDtune::command(), BLCMDtubs::command(), BLCMDtrap::command(), BLCMDtrackermode::command(), BLCMDtrackerplane::command(), BLCMDtracker::command(), BLCMDtrackcuts::command(), BLCMDtrace::command(), BLCMDtotalenergy::command(), BLCMDtorus::command(), BLCMDtimentuple::command(), BLCMDstart::command(), BLCMDsphere::command(), BLCMDspacechargelw::command(), BLCMDspacecharge::command(), BLCMDsolenoid::command(), BLCMDshowmaterial::command(), BLCMDsetdecay::command(), BLCMDreference::command(), BLCMDprofile::command(), BLCMDprintf::command(), BLCMDpolycone::command(), BLCMDpillbox::command(), BLCMDphysics::command(), BLCMDparticlesource::command(), BLCMDparticlefilter::command(), BLCMDparticlecolor::command(), BLCMDntuple::command(), BLCMDnewparticlentuple::command(), BLCMDmuminuscapturefix::command(), BLCMDmultipole::command(), BLCMDmovie::command(), BLCMDidealsectorbend::command(), BLCMDhelicalharmonic::command(), BLCMDhelicaldipole::command(), BLGroup::command(), BLCMDgeometry::command(), BLCMDgenericquad::command(), BLCMDgenericbend::command(), BLCMDg4ui::command(), BLCMDfieldmap::command(), BLCMDfieldlines::command(), BLCMDfieldexpr::command(), BLCMDextrusion::command(), BLCMDeventcuts::command(), BLCMDcornerarc::command(), BLCMDcorner::command(), BLCMDcollective::command(), BLCMDbug1021::command(), BLCMDbox::command(), BLCMDbeamlossntuple::command(), and BLCMDabsorber::command().
00384 { 00385 G4String indent1(commandName()); 00386 do { indent1 += " "; } while(indent1.size() < IndentDesc.size()); 00387 indent1 += name; 00388 do { indent1 += " "; } while(indent1.size() < IndentArg.size()); 00389 printArgs(indent1); 00390 }
void BLCommand::print | ( | G4String | name, | |
BLArgumentMap & | namedArgs | |||
) |
Print() -- alternate version for commands with special arguments. does not use defineNamedArgs() to print arguments, but rather prints namedArgs.
References commandName(), IndentArg(), IndentDesc(), printArgString, and wrapWords().
00393 { 00394 G4String indent1(commandName()); 00395 do { indent1 += " "; } while(indent1.size() < IndentDesc.size()); 00396 indent1 += name; 00397 do { indent1 += " "; } while(indent1.size() < IndentArg.size()); 00398 printArgString = ""; 00399 BLArgumentMap::iterator i; 00400 for(i=namedArgs.begin(); i!=namedArgs.end(); ++i) { 00401 printArgString += i->first; 00402 printArgString += "="; 00403 printArgString += i->second; 00404 printArgString += "\n"; 00405 } 00406 printf("%s",wrapWords(printArgString,indent1,IndentArg).c_str()); 00407 }
virtual G4String BLCommand::getName | ( | ) | const [inline, virtual] |
getName() returns the element's name; do not confuse this with commandName(). Re-defined by BLElement.
Reimplemented in BLElement, and BLCMDtracker.
BLCmdType BLCommand::getCmdType | ( | ) | [inline] |
getCmdType() returns the type of this command
References type.
Referenced by BLCommandAlias::BLCommandAlias().
00287 { return type; }
static bool BLCommand::isValidCommand | ( | G4String & | cmd | ) | [inline, static] |
isValidCommand() returns true if cmd is a valid command.
References mapCommand.
Referenced by main().
00291 { return mapCommand != 0 && mapCommand->count(cmd) > 0; }
int BLCommand::doCommand | ( | G4String & | line | ) | [static] |
doCommand() will parse line and perform a single command. Returns 0 if OK, -1 if error.
References ARGNAME, ARGVALUE, nextToken(), NONE, parseArgs(), printError(), and type.
Referenced by BLCMDlist::command(), BLCMDif::command(), BLCMDdo::command(), Macro::command(), main(), and readFile().
00410 { 00411 BLArgumentVector argv; 00412 BLArgumentMap namedArgs; 00413 G4String::size_type place = 0; 00414 TokenType type; 00415 00416 if(line.size() < 1) return 0; 00417 char c = line.c_str()[0]; 00418 if(c == '#') return 0; 00419 if(c == '*') { 00420 printf("%s\n",line.c_str()); 00421 return 0; 00422 } 00423 if(c == '!') { 00424 printf("%s\n",line.c_str()); 00425 fflush(stdout); 00426 system(line.c_str()+1); 00427 return 0; 00428 } 00429 if(c == '/') { 00430 printf("%s\n",line.c_str()); 00431 G4UImanager* UI = G4UImanager::GetUIpointer(); 00432 UI->ApplyCommand(line.c_str()); 00433 return 0; 00434 } 00435 00436 G4String cmd = nextToken(line,place,type); 00437 switch(type) { 00438 case NONE: 00439 return 0; // line with only whitespace 00440 case ARGVALUE: 00441 break; 00442 case ARGNAME: 00443 printError("Syntax Error"); 00444 return -1; 00445 } 00446 00447 if(parseArgs(line.substr(place),argv,namedArgs) < 0) 00448 return -1; 00449 00450 int retval; 00451 if((*mapCommand).count(cmd) > 0) { 00452 retval = (*mapCommand)[cmd]->command(argv,namedArgs); 00453 } else { 00454 retval = -1; 00455 printError("Unknown command '%s'",cmd.c_str()); 00456 } 00457 00458 return retval; 00459 }
int BLCommand::parseArgs | ( | const G4String & | line, | |
BLArgumentVector & | argv, | |||
BLArgumentMap & | namedArgs | |||
) | [static] |
parseArgs() will parse the arguments of a command line. Arguments are appended to argv[] and added to namedArgs. Returns 0 if OK, -1 if syntax error.
References ARGNAME, ARGVALUE, BLParam::expand(), nextToken(), NONE, Param, printError(), and type.
Referenced by BLCMDif::command(), doCommand(), BLFieldMap::readFile(), BLCoil::readMapFile(), and BLManager::setSteppingFormat().
00463 { 00464 G4String::size_type place = 0; 00465 while(place < line.size()) { 00466 TokenType type; 00467 G4String arg = nextToken(line,place,type), val; 00468 switch(type) { 00469 case NONE: 00470 break; 00471 case ARGNAME: 00472 val = nextToken(line,place,type); 00473 if(type != ARGVALUE) { 00474 printError("Syntax Error"); 00475 return -1; 00476 } 00477 namedArgs[arg] = Param.expand(val); 00478 break; 00479 case ARGVALUE: 00480 argv.push_back(Param.expand(arg)); 00481 break; 00482 } 00483 } 00484 return 0; 00485 }
int BLCommand::readFile | ( | G4String | filename | ) | [static] |
readFile() reads a file of commands and executes them. "-" is stdin. Returns the number of errors encountered, or -1 if filename cannot be read.
References doCommand(), getErrorCount(), getNextCommand(), in, and printError().
Referenced by BLCMDinclude::command(), and main().
00551 { 00552 std::istream *save = in; 00553 00554 std::ifstream fin; 00555 if(filename == "-") { 00556 in = &std::cin; 00557 } else { 00558 #ifdef WIN32 00559 fin.open(filename.c_str(),fin.in|fin.binary); 00560 #else 00561 fin.open(filename.c_str()); 00562 #endif 00563 in = &fin; 00564 } 00565 if(in == 0 || !in->good()) { 00566 printError("Cannot open file '%s'",filename.c_str()); 00567 return -1; 00568 } 00569 00570 int errorCount = getErrorCount(); 00571 00572 while(in->good()) { 00573 G4String *line = getNextCommand(); 00574 if(!line || line->find("exit") == 0) break; 00575 doCommand(*line); 00576 } 00577 00578 fin.close(); 00579 if(in == &std::cin) std::cout << std::endl; 00580 00581 in = save; 00582 return getErrorCount() - errorCount; 00583 }
void BLCommand::printError | ( | const char * | fmt, | |
... | ||||
) | [static] |
printError() prints an error message, using sprintf-style args. It also increments the errorCount.
References errors.
Referenced by BLCMDpillbox::argChanged(), argDouble(), argDouble(), argInt(), argInt(), argString(), BLWindowShape::BLWindowShape(), BLCMDzntuple::callback(), BLCMDtrackermode::callback(), BLCMDtotalenergy::callback(), SetDecayInstance::callback(), BLCMDprintfield::callback(), BLCMDvirtualdetector::command(), BLCMDusertrackfilter::command(), BLCMDtune::command(), BLCMDtubs::command(), BLCMDtrap::command(), BLCMDtrackermode::command(), BLCMDtrackerplane::command(), BLCMDtracker::command(), BLCMDtrackcuts::command(), BLCMDtotalenergy::command(), BLCMDtorus::command(), BLCMDtimentuple::command(), BLCMDtest::command(), BLCMDsphere::command(), BLCMDspacechargelw::command(), BLCMDspacecharge::command(), BLCMDsolenoid::command(), BLCMDshowmaterial::command(), BLCMDsetdecay::command(), BLCMDreference::command(), BLCMDrandomseed::command(), BLCMDprofile::command(), BLCMDprobefield::command(), BLCMDprintfield::command(), BLCMDprintf::command(), BLCMDpolycone::command(), BLCMDplace::command(), BLCMDpillbox::command(), BLCMDphysics::command(), BLCMDparticlesource::command(), BLCMDparticlefilter::command(), BLCMDparticlecolor::command(), BLCMDoutput::command(), BLCMDntuple::command(), BLCMDnewparticlentuple::command(), BLCMDmuminuscapturefix::command(), BLCMDmultipole::command(), BLCMDmaterial::command(), BLCMDinclude::command(), BLCMDif::command(), BLCMDidealsectorbend::command(), BLCMDhelicalharmonic::command(), BLCMDhelicaldipole::command(), BLGroup::command(), BLCMDgenericquad::command(), BLCMDgenericbend::command(), BLCMDg4ui::command(), BLCMDfieldntuple::command(), BLCMDfieldmap::command(), BLCMDfieldlines::command(), BLCMDfieldexpr::command(), BLCMDextrusion::command(), BLCMDendgroup::command(), BLCMDdo::command(), Macro::command(), BLCMDdefine::command(), BLCMDcosmicraybeam::command(), BLCMDcornerarc::command(), BLCMDcorner::command(), BLCMDcoil::command(), BLCMDbox::command(), BLCMDbeamlossntuple::command(), BLCMDbeam::command(), BLCMDabsorber::command(), BLCMDvirtualdetector::construct(), BLCMDusertrackfilter::construct(), BLCMDtrackerplane::construct(), BLCMDparticlefilter::construct(), BLCMDgenericbend::construct(), BLNTuple::create(), BLTune::defineTunableArg(), BLCMDprintfield::do_cylinder(), BLCMDprintfield::do_grid(), BLCMDprintfield::do_points(), BLCMDprintfield::do_print(), doCommand(), BLParam::expand(), SetDecayInstance::fatalError(), FOR009NTuple::FOR009NTuple(), GenericBendField::GenericBendField(), GenericQuadField::GenericQuadField(), BLCoordinates::getCoordinateType(), BLParam::getInt(), getMaterial(), BLParam::getString(), getVisAttrib(), GridImpl::handleCommand(), handleNamedArgs(), BLCMDplace::handleNamedArgs(), BLCMDtracker::handlePreviousTracks(), BLCMDbeam::init(), BLCMDlist::listParticleDetails(), BLCMDfieldntuple::Loop::Loop(), MultipoleField::MultipoleField(), BLCMDtrace::newTrace(), parseArgs(), BLGroup::placeElement(), BLFieldMap::readFile(), readFile(), BLCMDeventcuts::readFile(), BLCoil::readMapFile(), registerCommand(), CylinderImpl::setField(), GridImpl::setField(), setPos(), BLCMDpolycone::setup(), BLCMDextrusion::setup(), BLCMDcollective::setupFieldPoint(), BLCMDntuple::setupFirstEvent(), stringToRotationMatrix(), TrackerPlaneInstance::TrackerPlaneInstance(), BLTune::update(), and BLCMDprofile::Entry::UserZSteppingAction().
00071 { 00072 va_list ap; 00073 va_start(ap,fmt); 00074 fprintf(stdout,"***"); 00075 vfprintf(stdout,fmt,ap); 00076 fprintf(stdout,"\n"); 00077 ++errors; 00078 }
static int BLCommand::getErrorCount | ( | ) | [inline, static] |
getErrorCount() will return the number of errors so far.
References errors.
Referenced by main(), and readFile().
00313 { return errors; }
G4String * BLCommand::getNextCommand | ( | ) | [static] |
getNextCommand() returns the next command. backslash-newline has been handled, and the line is stripped of whitespace at both ends. returns 0 if error or EOF. The pointer should NOT be deleted.
References in, and BLSignal::setSignalReceived().
Referenced by BLCMDif::command(), BLCMDexit::command(), BLCMDdo::command(), and readFile().
00586 { 00587 static G4String line; 00588 00589 if(in == &std::cin) { 00590 BLSignal::setSignalReceived(true); 00591 std::cout << "cmd: "; 00592 } 00593 00594 char tmp[1024+1]; 00595 00596 do { 00597 if(!in->good()) return 0; 00598 in->getline(tmp,sizeof(tmp)); 00599 if(strchr(tmp,'\r')) *strchr(tmp,'\r') = '\0'; 00600 line = tmp; 00601 } while(line.size() == 0); 00602 00603 // handle continuation lines (ending with \) 00604 while(line[line.size()-1] == '\\' && in->good()) { 00605 line[line.size()-1] = ' '; 00606 in->getline(tmp,sizeof(tmp)); 00607 if(strchr(tmp,'\r')) *strchr(tmp,'\r') = '\0'; 00608 line += tmp; 00609 } 00610 00611 if(in == &std::cin) 00612 BLSignal::setSignalReceived(false); 00613 00614 // trim whitespace 00615 G4String::size_type i = line.find_first_not_of(" \t\r\n\v"); 00616 if(i == line.npos) i = line.size(); 00617 line.erase(0,i); 00618 while((i=line.find_last_of(" \t\r\n\v")) != line.npos) { 00619 if(i != line.size()-1) break; 00620 line.erase(i); 00621 } 00622 00623 return &line; 00624 }
BLCommandPos BLCommand::getPos | ( | ) | [static] |
getPos() returns the current position of the Command input stream
References in.
Referenced by BLCMDdo::command().
00627 { 00628 BLCommandPos pos(in); 00629 return pos; 00630 }
void BLCommand::setPos | ( | BLCommandPos & | pos | ) |
setPos() will set the Command input stream to a specified position
References BLCommandPos::in, in, BLCommandPos::pos, and printError().
Referenced by BLCMDdo::command().
00633 { 00634 if(in != pos.in) { 00635 printError("Invalid BLCommand setPos()"); 00636 return; 00637 } 00638 00639 in->seekg(pos.pos); 00640 }
G4Material * BLCommand::getMaterial | ( | G4String | materialName, | |
bool | error = true | |||
) | [static] |
getMaterial() searches the G4Material list and returns the entry corresponding to name. Searches the NIST database if the material is not already defined. Prepends "G4_" if necessary. prints an error and exits if the material is not found, so all materials MUST be defined before they are used, unless they can be found in the geant4 NIST database.
References printError().
Referenced by BLCMDvirtualdetector::command(), BLCMDusertrackfilter::command(), BLCMDtubs::command(), BLCMDtrap::command(), BLCMDtrackerplane::command(), BLCMDtorus::command(), BLCMDsphere::command(), BLCMDshowmaterial::command(), BLCMDpolycone::command(), BLCMDpillbox::command(), BLCMDparticlefilter::command(), BLCMDmultipole::command(), BLCMDmaterial::command(), BLCMDidealsectorbend::command(), BLGroup::command(), BLCMDgenericquad::command(), BLCMDgenericbend::command(), BLCMDextrusion::command(), BLCMDcorner::command(), BLCMDcoil::command(), BLCMDbox::command(), BLCMDabsorber::command(), BLCMDvirtualdetector::construct(), BLCMDusertrackfilter::construct(), BLCMDtubs::construct(), BLCMDtrap::construct(), BLCMDtrackerplane::construct(), BLCMDtorus::construct(), BLCMDsphere::construct(), BLCMDsolenoid::construct(), BLCMDpolycone::construct(), BLCMDpillbox::construct(), BLCMDparticlefilter::construct(), BLCMDmultipole::construct(), BLCMDidealsectorbend::construct(), BLGroup::construct(), BLCMDgenericquad::construct(), BLCMDgenericbend::construct(), BLCMDextrusion::construct(), BLCMDcorner::construct(), BLCMDbox::construct(), and BLCMDabsorber::construct().
00643 { 00644 const G4String G4("G4_"); 00645 G4NistManager *m = G4NistManager::Instance(); 00646 00647 // first, check if it has already been constructed 00648 G4Material *mat = G4Material::GetMaterial(materialName,false); 00649 if(mat) return mat; 00650 mat = G4Material::GetMaterial(G4+materialName,false); 00651 if(mat) return mat; 00652 00653 // Check for alias 00654 // NOTE: these materials are also listed in BLCMDmaterial::help() 00655 if(materialName == "Air") materialName = "AIR"; 00656 if(materialName == "H2O") materialName = "WATER"; 00657 if(materialName == "LH2") materialName = "lH2"; 00658 if(materialName == "Vacuum") { 00659 // preserve the name "Vacuum" 00660 G4Material *g = m->FindOrBuildMaterial("G4_Galactic"); 00661 G4Material *v = new G4Material(materialName, 00662 g->GetDensity(),1,g->GetState(),g->GetTemperature(), 00663 g->GetPressure()); 00664 v->AddMaterial(g,1.0); 00665 return v; 00666 } 00667 if(materialName == "Scintillator") { 00668 // preserve the name "Scintillator" 00669 G4Material *g = m->FindOrBuildMaterial("G4_POLYSTYRENE"); 00670 G4Material *v = new G4Material(materialName, 00671 g->GetDensity(),1,g->GetState(),g->GetTemperature(), 00672 g->GetPressure()); 00673 v->AddMaterial(g,1.0); 00674 return v; 00675 } 00676 if(materialName == "Stainless304") { 00677 // ignore optional components < 1% 00678 G4Material *v = new G4Material(materialName,8.01*g/cm3,4, 00679 kStateSolid); 00680 G4Material *Cr = m->FindOrBuildMaterial("G4_Cr"); 00681 G4Material *Ni = m->FindOrBuildMaterial("G4_Ni"); 00682 G4Material *Mn = m->FindOrBuildMaterial("G4_Mn"); 00683 G4Material *Fe = m->FindOrBuildMaterial("G4_Fe"); 00684 v->AddMaterial(Cr,0.19); 00685 v->AddMaterial(Ni,0.10); 00686 v->AddMaterial(Mn,0.01); 00687 v->AddMaterial(Fe,0.70); 00688 return v; 00689 } 00690 if(materialName == "Stainless316") { 00691 // ignore optional components < 1% 00692 G4Material *v = new G4Material(materialName,8.01*g/cm3,5, 00693 kStateSolid); 00694 G4Material *Cr = m->FindOrBuildMaterial("G4_Cr"); 00695 G4Material *Ni = m->FindOrBuildMaterial("G4_Ni"); 00696 G4Material *Mn = m->FindOrBuildMaterial("G4_Mn"); 00697 G4Material *Mo = m->FindOrBuildMaterial("G4_Mo"); 00698 G4Material *Fe = m->FindOrBuildMaterial("G4_Fe"); 00699 v->AddMaterial(Cr,0.18); 00700 v->AddMaterial(Ni,0.12); 00701 v->AddMaterial(Mn,0.01); 00702 v->AddMaterial(Mo,0.025); 00703 v->AddMaterial(Fe,0.665); 00704 return v; 00705 } 00706 if(materialName == "lHe" || materialName == "LHe") { 00707 G4Material *v = new G4Material(materialName,0.1249*g/cm3,1, 00708 kStateLiquid); 00709 G4Material *He = m->FindOrBuildMaterial("G4_He"); 00710 v->AddMaterial(He,1.0); 00711 return v; 00712 } 00713 00714 // all materials in the database begin "G4_". 00715 if(materialName.find(G4) == 0) 00716 mat = m->FindOrBuildMaterial(materialName); 00717 else 00718 mat = m->FindOrBuildMaterial(G4+materialName); 00719 if(mat) return mat; 00720 if(!error) { 00721 printError("getMaterial: cannot find material '%s'", 00722 materialName.c_str()); 00723 return getMaterial("Vacuum"); 00724 } 00725 00726 G4Exception("getMaterial","Material not found",FatalException, 00727 materialName.c_str()); 00728 return 0; 00729 }
G4VisAttributes * BLCommand::getVisAttrib | ( | G4String | color | ) | [static] |
getVisAttrib() returns the appropriate G4VisAttributes.
References getList(), and printError().
Referenced by BLCMDparticlecolor::BLCMDparticlecolor(), BLCMDshowmaterial::command(), BLCMDparticlecolor::command(), BLCMDvirtualdetector::construct(), BLCMDusertrackfilter::construct(), BLCMDtubs::construct(), BLCMDtrap::construct(), BLCMDtrackerplane::construct(), BLCMDtorus::construct(), BLCMDsphere::construct(), BLCMDsolenoid::construct(), BLCMDpolycone::construct(), BLCMDparticlefilter::construct(), BLCMDmultipole::construct(), BLCMDidealsectorbend::construct(), BLGroup::construct(), BLCMDgenericquad::construct(), BLCMDgenericbend::construct(), BLCMDextrusion::construct(), BLCMDcorner::construct(), BLCMDbox::construct(), BLCMDabsorber::construct(), and BLCMDfieldlines::generateOneFieldLine().
00732 { 00733 G4VisAttributes *p=0; 00734 00735 std::vector<G4double> v = getList(color,','); 00736 if(v.size() == 3) { 00737 p = new G4VisAttributes(true,G4Color(v[0],v[1],v[2])); 00738 } else if(v.size() == 4) { 00739 p = new G4VisAttributes(true,G4Color(v[0],v[1],v[2],v[3])); 00740 } else { 00741 p = new G4VisAttributes(G4VisAttributes::GetInvisible()); 00742 if(color.size() > 0 && toupper(color.c_str()[0]) != 'I') { 00743 printError("Invalid color '%s'",color.c_str()); 00744 } 00745 } 00746 00747 p->SetDaughtersInvisible(false); 00748 00749 return p; 00750 }
G4RotationMatrix * BLCommand::stringToRotationMatrix | ( | G4String | rotation | ) | [static] |
stringToRotationMatrix() converts a string "X90,Y45" into a G4RotationMatrix. This is an active rotation, in that the object is first rotated around the parent's X axis by 90 degrees, then the object is further rotated around the parent's Y axis by 45 degrees. The return value points to a G4RotationMatrix on the heap, so it is persistent. Angles are in degrees, can have decimals, and can be negative. Axes are X, Y, Z.
References getDouble(), printError(), and splitString().
Referenced by BLCMDstart::command(), BLCMDreference::command(), BLCMDplace::command(), BLCMDcornerarc::command(), BLCMDcorner::command(), BLCMDbeam::command(), and BLCMDidealsectorbend::construct().
00753 { 00754 // We apply successive rotations OF THE OBJECT around the FIXED 00755 // axes of the parent's local coordinates; rotations are applied 00756 // left-to-right (rotation="r1,r2,r3" => apply r1 then r2 then r3). 00757 G4RotationMatrix *rot = new G4RotationMatrix(); 00758 std::vector<G4String> v = splitString(rotation,",",true); 00759 for(unsigned i=0; i<v.size(); ++i) { 00760 G4double angle=getDouble(v[i].substr(1)) * deg; 00761 if(gsl_isnan(angle)) { 00762 printError("Invalid rotation specification '%s'", 00763 rotation.c_str()); 00764 return 0; 00765 } 00766 G4RotationMatrix thisRotation; 00767 switch(v[i].c_str()[0]) { 00768 case 'X': case 'x': 00769 thisRotation = G4RotationMatrix(CLHEP::HepRotationX(angle)); 00770 break; 00771 case 'Y': case 'y': 00772 thisRotation = G4RotationMatrix(CLHEP::HepRotationY(angle)); 00773 break; 00774 case 'Z': case 'z': 00775 thisRotation = G4RotationMatrix(CLHEP::HepRotationZ(angle)); 00776 break; 00777 default: 00778 printError("Invalid rotation specification '%s'", 00779 rotation.c_str()); 00780 return 0; 00781 } 00782 *rot = thisRotation * *rot; 00783 } 00784 00785 return rot; 00786 }
void BLCommand::dumpRotation | ( | const G4RotationMatrix * | rot, | |
const char * | str | |||
) | [static] |
dumpRotation() dumps info about a rotation matrix to stdout.
Referenced by BLManager::displayGeometry().
00789 { 00790 if(!rot) { 00791 printf("%s: no rotation\n",str); 00792 return; 00793 } 00794 G4ThreeVector x(1.0,0.0,0.0), z(0.0,0.0,1.0); 00795 G4ThreeVector rx = *rot * x; 00796 G4ThreeVector rz = *rot * z; 00797 printf("%s: %.3f,%.3f,%.3f / %.3f,%.3f,%.3f / %.3f,%.3f,%.3f\n", 00798 str,rot->xx(),rot->xy(),rot->xz(),rot->yx(),rot->yy(),rot->yz(), 00799 rot->zx(),rot->zy(),rot->zz()); 00800 printf(" rot*x=%.3f,%.3f,%.3f rot*z = %.3f,%.3f,%.3f\n", 00801 rx[0],rx[1],rx[2],rz[0],rz[1],rz[2]); 00802 }
std::vector< G4String > BLCommand::splitString | ( | const G4String & | s, | |
const G4String & | delim, | |||
bool | trim = false | |||
) | [static] |
splitString() splits a string at each instance of any character in delim, returning a vector<G4String>. If trim is true, each returned string has whitespace removed from its front and rear. Successive delimiters, or delimiters at the beginning or end, generate an empty string.
Referenced by SetDecayInstance::callback(), BLCMDtrackcuts::command(), BLCMDtotalenergy::command(), BLCMDphysics::command(), getList(), SetDecayInstance::isMatch(), BLCMDlist::listParticleDetails(), BLCMDparticlefilter::setup(), BLCMDextrusion::setup(), and stringToRotationMatrix().
00806 { 00807 G4String tmp(s), p; 00808 std::vector<G4String> v; 00809 while(tmp.size() > 0) { 00810 G4String::size_type i=tmp.find_first_of(delim); 00811 if(i > tmp.size()) i = tmp.size(); 00812 p = tmp.substr(0,i); 00813 if(trim) { 00814 while(p.size() > 0 && isspace(p.c_str()[0])) 00815 p.erase(0,1); 00816 while(p.size() > 0 && isspace(p.c_str()[p.size()-1])) 00817 p.erase(p.size()-1,1); 00818 } 00819 v.push_back(p); 00820 tmp.erase(0,i+1); 00821 } 00822 00823 return v; 00824 }
static double BLCommand::getDouble | ( | const G4String & | s | ) | [inline, static] |
getDouble() converts a string to a double, returning nan if the string is not a valid expression using double constants and standard C operators and functions; whitespace is permitted as in C but an empty or all-whitespace string is invalid. Callers can use std::isnan(double) or gsl_isnan(double) to test for validity.
References BLEvaluator::evaluate().
Referenced by getList(), and stringToRotationMatrix().
00367 { BLEvaluator e; return e.evaluate(s); }
std::vector< G4double > BLCommand::getList | ( | const G4String & | s, | |
const G4String & | delim | |||
) | [static] |
getList() converts a string containing a delimited list of double expressions to a vector<G4double>. Any character in delim separates entries. Functions and operators known to BLEvaluator can be used in each entry of the list. Empty entries (null or consisting only of whitespace) are invalid. Returns an empty list if any entry is an invalid expression.
References getDouble(), and splitString().
Referenced by BLCMDzntuple::callback(), BLCMDprofile::command(), BLCMDprintf::command(), BLCMDfieldlines::command(), GenericBendField::GenericBendField(), GenericQuadField::GenericQuadField(), getVisAttrib(), BLCMDfieldntuple::Loop::Loop(), BLCMDpolycone::setup(), BLCMDextrusion::setup(), and BLCMDcollective::setupFieldPoint().
00828 { 00829 std::vector<G4String> vect_s = splitString(s,delim,true); 00830 std::vector<G4double> retval; 00831 00832 for(unsigned i=0; i<vect_s.size(); ++i) { 00833 G4double val=getDouble(vect_s[i]); 00834 if(gsl_isnan(val)) { 00835 retval.clear(); 00836 break; 00837 } 00838 retval.push_back(val); 00839 } 00840 00841 return retval; 00842 }
friend class BLCMDplace [friend] |
friend class BLCMDhelp [friend] |
std::map< G4String, BLCommand * > * BLCommand::mapCommand [static, private] |
Referenced by BLCMDhelp::command(), deleteCommand(), isValidCommand(), and registerCommand().
int BLCommand::errors = 0 [static, private] |
Referenced by getErrorCount(), and printError().
std::istream * BLCommand::in = 0 [static, private] |
Reimplemented in BLCMDprobefield.
Referenced by getNextCommand(), getPos(), BLCMDtracker::handlePreviousTracks(), readFile(), BLCMDeventcuts::readFile(), and setPos().
ArgumentMode BLCommand::argMode [protected] |
bool BLCommand::argFound [protected] |
Referenced by argDouble(), argInt(), argString(), argTunable(), handleNamedArgs(), and BLCMDplace::handleNamedArgs().
G4String BLCommand::argName [protected] |
Referenced by argDouble(), argInt(), argString(), argTunable(), handleNamedArgs(), and BLCMDplace::handleNamedArgs().
G4String BLCommand::argValue [protected] |
Referenced by argDouble(), argInt(), argString(), argTunable(), handleNamedArgs(), and BLCMDplace::handleNamedArgs().
G4String BLCommand::synopsis [protected] |
Referenced by help(), and setSynopsis().
G4String BLCommand::description [protected] |
G4String BLCommand::printArgString [protected] |
Referenced by argDouble(), argInt(), argString(), argTunable(), print(), and printArgs().
int BLCommand::nArgs [protected] |
Referenced by argDouble(), argInt(), argString(), argTunable(), and help().
int BLCommand::nFixed [protected] |
Referenced by argDouble(), argInt(), argString(), and help().
int BLCommand::nTunable [protected] |
Referenced by argTunable(), and help().
BLCmdType BLCommand::type [protected] |
Reimplemented in BLCMDbeam, and BLCMDprintfield.
Referenced by BLCMDtrackcuts::command(), doCommand(), getCmdType(), parseArgs(), and registerCommand().