#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 double | undefined () |
undefined() returns a quiet Not-A-Number, for initializing arguments to determine if the user set them or not. | |
static bool | isUndefined (double v) |
isUndefined() determines wheter an argument has been set. | |
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. NOTE: This is expensive and should not be used during tracking. | |
static void | dumpRotation (const G4RotationMatrix *rot, const char *str) |
dumpRotation() dumps info about a rotation matrix to stdout. NOTE: This is expensive and should not be used during tracking. | |
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. NOTE: This is expensive and should not be used during tracking. | |
static double | getDouble (const G4String &s) |
getDouble() converts a string expression 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. NOTE: This is expensive and should not be used during tracking. | |
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. NOTE: This is expensive and should not be used during tracking. | |
static bool | matchList (const G4String s, const G4String patternList) |
matchList() returns true if s matches any pattern in patternList, whch is a comma-separated list of file-glob patterns. NOTE: This is expensive and should not be used during tracking. | |
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().
00491 { 00492 // (add +- for particlecolor pi+=1,1,1) 00493 static const char namechars[] = ",+-ABCDEFGHIJKLMNOPQRSTUVWXYZ_" 00494 "abcdefghijklmnopqrstuvwxyz0123456789"; 00495 G4String::size_type i; 00496 00497 // check if previous token was ARGNAME 00498 if(line[place] == '=') { 00499 ++place; 00500 goto value; 00501 } 00502 00503 // skip initial whitespace 00504 while(place < line.size() && isspace(line[place])) ++place; 00505 00506 // check for ARGNAME 00507 if(isalnum(line[place]) || line[place] == '_') { 00508 i = line.find_first_not_of(namechars,place); 00509 if(i > place && i < line.size() && line[i] == '=' && 00510 line[i+1] != '=') { 00511 G4String retval = line.substr(place,i-place); 00512 place = i; 00513 type = ARGNAME; 00514 return retval; 00515 } 00516 } 00517 value: 00518 if(line[place] == '"') { 00519 ++place; 00520 i = line.find('"',place); 00521 if(i <line.size()) { 00522 G4String retval = line.substr(place,i-place); 00523 place = i + 1; 00524 type = ARGVALUE; 00525 return retval; 00526 } 00527 } else if(line[place] == '\'') { 00528 ++place; 00529 i = line.find('\'',place); 00530 if(i <line.size()) { 00531 G4String retval = line.substr(place,i-place); 00532 place = i + 1; 00533 type = ARGVALUE; 00534 return retval; 00535 } 00536 } 00537 00538 if(place >= line.size()) { 00539 type = NONE; 00540 return ""; 00541 } 00542 00543 // find next whitespace 00544 G4String::size_type start = place; 00545 while(place < line.size() && !isspace(line[place])) ++place; 00546 00547 type = ARGVALUE; 00548 00549 return line.substr(start,place-start); 00550 }
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().
00318 { 00319 G4String indent1(IndentDesc); 00320 indent1 += name; 00321 do { indent1 += " "; } while(indent1.size() < IndentArg.size()); 00322 printf("%s",wrapWords(_description,indent1,IndentArg).c_str()); 00323 }
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(), BLCMDlilens::BLCMDlilens(), 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(), BLCMDreweightprocess::BLCMDreweightprocess(), BLCMDrfdevice::BLCMDrfdevice(), 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().
00059 { 00060 type = _type; 00061 00062 if(!mapCommand) 00063 mapCommand = new std::map<G4String,BLCommand*>; 00064 if((*mapCommand).count(commandName()) > 0 && 00065 (*mapCommand)[commandName()] != this) 00066 printError("Attempt to re-define the command '%s'", 00067 commandName().c_str()); 00068 else 00069 (*mapCommand)[commandName()] = this; 00070 }
void BLCommand::deleteCommand | ( | G4String & | name | ) | [inline, protected] |
deleteCommand() will delete a command by name
References mapCommand.
Referenced by Macro::Macro().
00140 { 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(), BLCMDlilens::BLCMDlilens(), 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(), BLCMDreweightprocess::BLCMDreweightprocess(), BLCMDrfdevice::BLCMDrfdevice(), 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().
00148 { 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(), BLCMDlilens::BLCMDlilens(), 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(), BLCMDreweightprocess::BLCMDreweightprocess(), BLCMDrfdevice::BLCMDrfdevice(), 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().
00159 { 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(), BLCMDrfdevice::defineNamedArgs(), BLCMDreweightprocess::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(), BLCMDlilens::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().
00136 { 00137 switch(argMode) { 00138 case CHANGE: 00139 if(!permitChange) { 00140 if(argName == name) 00141 printError("%s: Argument '%s' is not permitted to change\n", 00142 commandName().c_str(),name.c_str()); 00143 break; 00144 } 00145 // flow into PROCESS 00146 case PROCESS: 00147 if(argFound || argName != name) return; 00148 argFound = true; 00149 var = argValue; 00150 break; 00151 case COUNT: 00152 ++nArgs; 00153 if(!permitChange) ++nFixed; 00154 break; 00155 case HELP: 00156 printArgDesc(name,_description+(permitChange?"":" #")); 00157 break; 00158 case PRINT: 00159 printArgString += name; 00160 printArgString += "="; 00161 printArgString += var; 00162 printArgString += "\n"; 00163 break; 00164 } 00165 }
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(), BLCMDrfdevice::defineNamedArgs(), BLCMDreweightprocess::defineNamedArgs(), BLCMDreference::defineNamedArgs(), BLCMDprintfield::defineNamedArgs(), BLCMDprintf::defineNamedArgs(), BLCMDpolycone::defineNamedArgs(), BLCMDplace::defineNamedArgs(), BLCMDpillbox::defineNamedArgs(), BLCMDphysics::defineNamedArgs(), BLCMDparticlefilter::defineNamedArgs(), BLCMDmuminuscapturefix::defineNamedArgs(), BLCMDmultipole::defineNamedArgs(), BLCMDmaterial::defineNamedArgs(), BLCMDlilens::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().
00169 { 00170 if(fmt == "") fmt = DefaultDoubleFmt; 00171 00172 switch(argMode) { 00173 case CHANGE: 00174 if(!permitChange) { 00175 if(argName == name) 00176 printError("%s: Argument '%s' is not permitted to change\n", 00177 commandName().c_str(),name.c_str()); 00178 break; 00179 } 00180 // flow into PROCESS 00181 case PROCESS: 00182 if(argFound || argName != name) return; 00183 argFound = true; 00184 { BLEvaluator e; 00185 G4double v = e.evaluate(argValue); 00186 if(e.status() != HepTool::Evaluator::OK) { 00187 printError("Invalid value for argument '%s'" 00188 " to command '%s'", argName.c_str(), 00189 commandName().c_str()); 00190 return; 00191 } 00192 var = v * units; 00193 } 00194 /**** 00195 { const char *p=argValue.c_str(); 00196 char *q; 00197 G4double v = strtod(p,&q); 00198 if(p == q || *q != '\0') { 00199 printError("Invalid value for argument '%s'" 00200 " to command '%s'", argName.c_str(), 00201 commandName().c_str()); 00202 return; 00203 } 00204 var = v * units; 00205 } 00206 ****/ 00207 break; 00208 case COUNT: 00209 ++nArgs; 00210 if(!permitChange) ++nFixed; 00211 break; 00212 case HELP: 00213 printArgDesc(name,_description+(permitChange?"":" #")); 00214 break; 00215 case PRINT: 00216 { char tmp[65]; 00217 snprintf(tmp,sizeof(tmp),fmt.c_str(),var/units); 00218 printArgString += name; 00219 printArgString += "="; 00220 printArgString += tmp; 00221 printArgString += "\n"; 00222 } 00223 break; 00224 } 00225 }
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 BLCMDrfdevice::defineNamedArgs(), BLCMDpillbox::defineNamedArgs(), BLCMDidealsectorbend::defineNamedArgs(), BLCMDgenericbend::defineNamedArgs(), BLCMDfieldmap::defineNamedArgs(), and BLCMDfieldexpr::defineNamedArgs().
00229 { 00230 if(fmt == "") fmt = DefaultDoubleFmt; 00231 00232 switch(argMode) { 00233 case CHANGE: 00234 case PROCESS: 00235 if(argFound || argName != name) return; 00236 argFound = true; 00237 BLTune::defineTunableArg(var,units,argValue); 00238 break; 00239 case HELP: 00240 printArgDesc(name,_description+" @"); 00241 break; 00242 case COUNT: 00243 ++nArgs; 00244 ++nTunable; 00245 break; 00246 case PRINT: 00247 { char tmp[65]; 00248 snprintf(tmp,sizeof(tmp),fmt.c_str(),var/units); 00249 printArgString += name; 00250 printArgString += "="; 00251 printArgString += tmp; 00252 printArgString += "\n"; 00253 } 00254 break; 00255 } 00256 }
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(), BLCMDtimentuple::defineNamedArgs(), BLCMDstart::defineNamedArgs(), BLCMDsphere::defineNamedArgs(), BLCMDspacechargelw::defineNamedArgs(), BLCMDspacecharge::defineNamedArgs(), BLCMDsolenoid::defineNamedArgs(), BLCMDrfdevice::defineNamedArgs(), BLCMDreference::defineNamedArgs(), BLCMDprobefield::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().
00260 { 00261 switch(argMode) { 00262 case CHANGE: 00263 if(!permitChange) { 00264 if(argName == name) 00265 printError("%s: Argument '%s' is not permitted to change\n", 00266 commandName().c_str(),name.c_str()); 00267 break; 00268 } 00269 // flow into PROCESS 00270 case PROCESS: 00271 if(argFound || argName != name) return; 00272 argFound = true; 00273 { BLEvaluator e; 00274 G4double v = e.evaluate(argValue); 00275 var = (G4int)(v+0.5); 00276 if(e.status() != HepTool::Evaluator::OK || 00277 fabs(var-v) > 0.001) { 00278 printError("Invalid value for argument '%s'" 00279 " to command '%s'", argName.c_str(), 00280 commandName().c_str()); 00281 return; 00282 } 00283 } 00284 /*** 00285 { const char *p=argValue.c_str(); 00286 char *q; 00287 G4int v = strtol(p,&q,0); 00288 if(p == q || *q != '\0') { 00289 printError("Invalid value for argument '%s'" 00290 " to command '%s'", argName.c_str(), 00291 commandName().c_str()); 00292 return; 00293 } 00294 var = v; 00295 } 00296 ***/ 00297 break; 00298 case COUNT: 00299 ++nArgs; 00300 if(!permitChange) ++nFixed; 00301 break; 00302 case HELP: 00303 printArgDesc(name,_description+(permitChange?"":" #")); 00304 break; 00305 case PRINT: 00306 { char tmp[65]; 00307 snprintf(tmp,sizeof(tmp),"%d",var); 00308 printArgString += name; 00309 printArgString += "="; 00310 printArgString += tmp; 00311 printArgString += "\n"; 00312 } 00313 break; 00314 } 00315 }
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(), BLCMDrfdevice::command(), BLCMDreweightprocess::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(), BLCMDlilens::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().
00326 { 00327 int retval = 0; 00328 argMode = PROCESS; 00329 00330 BLArgumentMap::iterator i; 00331 for(i=args.begin(); i!=args.end(); ++i) { 00332 argName = i->first; 00333 argValue = i->second; 00334 argFound = false; 00335 defineNamedArgs(); 00336 if(!argFound) { 00337 printError("Invalid argument '%s' to command '%s'", 00338 argName.c_str(),commandName().c_str()); 00339 retval = -1; 00340 } 00341 } 00342 00343 if(args.size() > 0) argChanged(); 00344 00345 return retval; 00346 }
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().
00354 { 00355 G4String str(commandName()); 00356 do { str += " "; } while(str.size() < IndentDesc.size()); 00357 printf("%s%s\n",str.c_str(),synopsis.c_str()); 00358 if(detailed) { 00359 if(description.rfind(": ") == description.size()-2) 00360 description += BLNTuple::getFormatList(); 00361 printf("\n%s",wrapWords(description,IndentDesc,IndentDesc).c_str()); 00362 nArgs = nFixed = nTunable = 0; 00363 argMode = COUNT; 00364 defineNamedArgs(); 00365 if(nArgs > 0) { 00366 printf("\n%sNamed Arguments", IndentDesc.c_str()); 00367 if(nFixed > 0) 00368 printf(" (#=cannot be changed in place cmd)"); 00369 if(nTunable > 0) printf(" (@=Tunable)"); 00370 printf(":\n"); 00371 argMode = HELP; 00372 defineNamedArgs(); 00373 } 00374 } 00375 }
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().
00084 { 00085 G4String retval(""), space(" "), line(""), word(""); 00086 G4String::size_type pos=0, next=0; 00087 bool eol=false; 00088 00089 while(pos < text.size()) { 00090 if(eol && isspace(text[pos])) { 00091 next = text.find_first_of("\n",pos); 00092 if(next == text.npos) next = text.size(); 00093 if(line.size() > 0) {retval += line; retval += "\n";} 00094 line = indent + text.substr(pos,next-pos); 00095 retval += line; 00096 retval += "\n"; 00097 line = ""; 00098 pos = next + 1; 00099 // eol = true; 00100 continue; 00101 } 00102 next = text.find_first_of(" \t\r\n",pos); 00103 if(next == text.npos) { 00104 word = text.substr(pos); 00105 next = text.size(); 00106 } else { 00107 word = text.substr(pos,next-pos); 00108 eol = (text[next] == '\n'); 00109 } 00110 if(word.size() > 0) { 00111 if(line.size() == 0) { 00112 if(retval.size() == 0) 00113 line = indent1; 00114 else 00115 line = indent; 00116 line += word; 00117 } else if(line.size()+word.size()+1 < width) { 00118 line += space; 00119 line += word; 00120 } else { 00121 retval += line; 00122 retval += "\n"; 00123 line = indent; 00124 line += word; 00125 } 00126 } 00127 pos = next + 1; 00128 } 00129 if(line.size() > 0) {retval += line; retval += "\n";} 00130 00131 return retval; 00132 }
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().
00378 { 00379 printArgString = ""; 00380 argMode = PRINT; 00381 defineNamedArgs(); 00382 printf("%s",wrapWords(printArgString,indent1,IndentArg).c_str()); 00383 }
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, BLCMDlilens, BLCMDlist, BLCMDmaterial, BLCMDmovie, BLCMDmultipole, BLCMDmuminuscapturefix, BLCMDnewparticlentuple, BLCMDntuple, BLCMDoutput, BLCMDparam, BLCMDparticlecolor, BLCMDparticlefilter, BLCMDparticlesource, BLCMDphysics, BLCMDpillbox, BLCMDplace, BLCMDpolycone, BLCMDprintf, BLCMDprintfield, BLCMDprobefield, BLCMDprofile, BLCMDrandomseed, BLCMDreference, BLCMDreweightprocess, BLCMDrfdevice, 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, BLCMDlilens, BLCMDlist, BLCMDmaterial, BLCMDmovie, BLCMDmultipole, BLCMDmuminuscapturefix, BLCMDnewparticlentuple, BLCMDntuple, BLCMDoutput, BLCMDparam, BLCMDparticlecolor, BLCMDparticlefilter, BLCMDparticlesource, BLCMDphysics, BLCMDpillbox, BLCMDplace, BLCMDpolycone, BLCMDprintf, BLCMDprintfield, BLCMDprobefield, BLCMDprofile, BLCMDrandomseed, BLCMDreference, BLCMDreweightprocess, BLCMDrfdevice, 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, BLCMDlilens, BLCMDlist, BLCMDmaterial, BLCMDmovie, BLCMDmultipole, BLCMDmuminuscapturefix, BLCMDnewparticlentuple, BLCMDntuple, BLCMDparticlecolor, BLCMDparticlefilter, BLCMDparticlesource, BLCMDphysics, BLCMDpillbox, BLCMDplace, BLCMDpolycone, BLCMDprintf, BLCMDprintfield, BLCMDprobefield, BLCMDprofile, BLCMDrandomseed, BLCMDreference, BLCMDreweightprocess, BLCMDrfdevice, 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().
00349 { 00350 if(argMode == HELP) printf("%s(none)\n",IndentDesc.c_str()); 00351 }
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, BLCMDrfdevice, 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(), BLCMDrfdevice::command(), BLCMDreweightprocess::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(), BLCMDlilens::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().
00386 { 00387 G4String indent1(commandName()); 00388 do { indent1 += " "; } while(indent1.size() < IndentDesc.size()); 00389 indent1 += name; 00390 do { indent1 += " "; } while(indent1.size() < IndentArg.size()); 00391 printArgs(indent1); 00392 }
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().
00395 { 00396 G4String indent1(commandName()); 00397 do { indent1 += " "; } while(indent1.size() < IndentDesc.size()); 00398 indent1 += name; 00399 do { indent1 += " "; } while(indent1.size() < IndentArg.size()); 00400 printArgString = ""; 00401 BLArgumentMap::iterator i; 00402 for(i=namedArgs.begin(); i!=namedArgs.end(); ++i) { 00403 printArgString += i->first; 00404 printArgString += "="; 00405 printArgString += i->second; 00406 printArgString += "\n"; 00407 } 00408 printf("%s",wrapWords(printArgString,indent1,IndentArg).c_str()); 00409 }
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.
double BLCommand::undefined | ( | ) | [static] |
undefined() returns a quiet Not-A-Number, for initializing arguments to determine if the user set them or not.
Referenced by BLCMDrfdevice::argChanged(), BLCMDrfdevice::BLCMDrfdevice(), RFdeviceField::reset(), RFdeviceField::RFdeviceField(), and RFdeviceField::UserSteppingAction().
bool BLCommand::isUndefined | ( | double | v | ) | [static] |
isUndefined() determines wheter an argument has been set.
Referenced by RFdeviceField::addFieldValue(), BLCMDrfdevice::argChanged(), BLCMDrfdevice::BLCMDrfdevice(), BLCMDrfdevice::construct(), RFdeviceField::show1step(), and RFdeviceField::UserSteppingAction().
BLCmdType BLCommand::getCmdType | ( | ) | [inline] |
getCmdType() returns the type of this command
References type.
Referenced by BLCommandAlias::BLCommandAlias().
00294 { return type; }
static bool BLCommand::isValidCommand | ( | G4String & | cmd | ) | [inline, static] |
isValidCommand() returns true if cmd is a valid command.
References mapCommand.
Referenced by main().
00298 { 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().
00412 { 00413 BLArgumentVector argv; 00414 BLArgumentMap namedArgs; 00415 G4String::size_type place = 0; 00416 TokenType type; 00417 00418 if(line.size() < 1) return 0; 00419 char c = line.c_str()[0]; 00420 if(c == '#') return 0; 00421 if(c == '*') { 00422 printf("%s\n",line.c_str()); 00423 return 0; 00424 } 00425 if(c == '!') { 00426 printf("%s\n",line.c_str()); 00427 fflush(stdout); 00428 system(line.c_str()+1); 00429 return 0; 00430 } 00431 if(c == '/') { 00432 printf("%s\n",line.c_str()); 00433 G4UImanager* UI = G4UImanager::GetUIpointer(); 00434 UI->ApplyCommand(line.c_str()); 00435 return 0; 00436 } 00437 00438 G4String cmd = nextToken(line,place,type); 00439 switch(type) { 00440 case NONE: 00441 return 0; // line with only whitespace 00442 case ARGVALUE: 00443 break; 00444 case ARGNAME: 00445 printError("Syntax Error"); 00446 return -1; 00447 } 00448 00449 if(parseArgs(line.substr(place),argv,namedArgs) < 0) 00450 return -1; 00451 00452 int retval; 00453 if((*mapCommand).count(cmd) > 0) { 00454 retval = (*mapCommand)[cmd]->command(argv,namedArgs); 00455 } else { 00456 retval = -1; 00457 printError("Unknown command '%s'",cmd.c_str()); 00458 } 00459 00460 return retval; 00461 }
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().
00465 { 00466 G4String::size_type place = 0; 00467 while(place < line.size()) { 00468 TokenType type; 00469 G4String arg = nextToken(line,place,type), val; 00470 switch(type) { 00471 case NONE: 00472 break; 00473 case ARGNAME: 00474 val = nextToken(line,place,type); 00475 if(type != ARGVALUE) { 00476 printError("Syntax Error"); 00477 return -1; 00478 } 00479 namedArgs[arg] = Param.expand(val); 00480 break; 00481 case ARGVALUE: 00482 argv.push_back(Param.expand(arg)); 00483 break; 00484 } 00485 } 00486 return 0; 00487 }
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().
00553 { 00554 std::istream *save = in; 00555 00556 std::ifstream fin; 00557 if(filename == "-") { 00558 in = &std::cin; 00559 } else { 00560 #ifdef WIN32 00561 fin.open(filename.c_str(),fin.in|fin.binary); 00562 #else 00563 fin.open(filename.c_str()); 00564 #endif 00565 in = &fin; 00566 } 00567 if(in == 0 || !in->good()) { 00568 printError("Cannot open file '%s'",filename.c_str()); 00569 return -1; 00570 } 00571 00572 int errorCount = getErrorCount(); 00573 00574 while(in->good()) { 00575 G4String *line = getNextCommand(); 00576 if(!line || line->find("exit") == 0) break; 00577 doCommand(*line); 00578 } 00579 00580 fin.close(); 00581 if(in == &std::cin) std::cout << std::endl; 00582 00583 in = save; 00584 return getErrorCount() - errorCount; 00585 }
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 BLCMDrfdevice::argChanged(), 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(), BLCMDrfdevice::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(), BLCMDlilens::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(), MaterialFilter::MaterialFilter(), 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().
00073 { 00074 va_list ap; 00075 va_start(ap,fmt); 00076 fprintf(stdout,"***"); 00077 vfprintf(stdout,fmt,ap); 00078 fprintf(stdout,"\n"); 00079 ++errors; 00080 }
static int BLCommand::getErrorCount | ( | ) | [inline, static] |
getErrorCount() will return the number of errors so far.
References errors.
Referenced by main(), and readFile().
00320 { 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().
00588 { 00589 static G4String line; 00590 00591 if(in == &std::cin) { 00592 BLSignal::setSignalReceived(true); 00593 std::cout << "cmd: "; 00594 } 00595 00596 char tmp[1024+1]; 00597 00598 do { 00599 if(!in->good()) return 0; 00600 in->getline(tmp,sizeof(tmp)); 00601 // trim trailing whitespace (handle "...\\ \r" from Windows) 00602 for(int i=strlen(tmp)-1; i>=0&&isspace(tmp[i]); --i) 00603 tmp[i] = '\0'; 00604 line = tmp; 00605 } while(line.size() == 0); 00606 00607 // handle continuation lines (ending with \) 00608 while(line[line.size()-1] == '\\' && in->good()) { 00609 line[line.size()-1] = ' '; 00610 in->getline(tmp,sizeof(tmp)); 00611 // trim trailing whitespace (handle "...\\ \r" from Windows) 00612 for(int i=strlen(tmp)-1; i>=0&&isspace(tmp[i]); --i) 00613 tmp[i] = '\0'; 00614 line += tmp; 00615 } 00616 00617 if(in == &std::cin) 00618 BLSignal::setSignalReceived(false); 00619 00620 // trim whitespace 00621 G4String::size_type i = line.find_first_not_of(" \t\r\n\v"); 00622 if(i == line.npos) i = line.size(); 00623 line.erase(0,i); 00624 while((i=line.find_last_of(" \t\r\n\v")) != line.npos) { 00625 if(i != line.size()-1) break; 00626 line.erase(i); 00627 } 00628 00629 return &line; 00630 }
BLCommandPos BLCommand::getPos | ( | ) | [static] |
getPos() returns the current position of the Command input stream
References in.
Referenced by BLCMDdo::command().
00633 { 00634 BLCommandPos pos(in); 00635 return pos; 00636 }
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().
00639 { 00640 if(in != pos.in) { 00641 printError("Invalid BLCommand setPos()"); 00642 return; 00643 } 00644 00645 in->seekg(pos.pos); 00646 }
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(), BLCMDrfdevice::command(), BLCMDpolycone::command(), BLCMDpillbox::command(), BLCMDparticlefilter::command(), BLCMDmultipole::command(), BLCMDmaterial::command(), BLCMDlilens::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(), BLCMDrfdevice::construct(), BLCMDpolycone::construct(), BLCMDpillbox::construct(), BLCMDparticlefilter::construct(), BLCMDmultipole::construct(), BLCMDlilens::construct(), BLCMDidealsectorbend::construct(), BLGroup::construct(), BLCMDgenericquad::construct(), BLCMDgenericbend::construct(), BLCMDextrusion::construct(), BLCMDcorner::construct(), BLCMDbox::construct(), and BLCMDabsorber::construct().
00649 { 00650 const G4String G4("G4_"); 00651 G4NistManager *m = G4NistManager::Instance(); 00652 00653 // first, check if it has already been constructed 00654 G4Material *mat = G4Material::GetMaterial(materialName,false); 00655 if(mat) return mat; 00656 mat = G4Material::GetMaterial(G4+materialName,false); 00657 if(mat) return mat; 00658 00659 // Check for alias 00660 // NOTE: these materials are also listed in BLCMDmaterial::help() 00661 if(materialName == "Air") materialName = "AIR"; 00662 if(materialName == "H2O") materialName = "WATER"; 00663 if(materialName == "LH2") materialName = "lH2"; 00664 if(materialName == "Vacuum") { 00665 // preserve the name "Vacuum" 00666 G4Material *g = m->FindOrBuildMaterial("G4_Galactic"); 00667 G4Material *v = new G4Material(materialName, 00668 g->GetDensity(),1,g->GetState(),g->GetTemperature(), 00669 g->GetPressure()); 00670 v->AddMaterial(g,1.0); 00671 return v; 00672 } 00673 if(materialName == "Scintillator") { 00674 // preserve the name "Scintillator" 00675 G4Material *g = m->FindOrBuildMaterial("G4_POLYSTYRENE"); 00676 G4Material *v = new G4Material(materialName, 00677 g->GetDensity(),1,g->GetState(),g->GetTemperature(), 00678 g->GetPressure()); 00679 v->AddMaterial(g,1.0); 00680 return v; 00681 } 00682 if(materialName == "Stainless304") { 00683 // ignore optional components < 1% 00684 G4Material *v = new G4Material(materialName,8.01*g/cm3,4, 00685 kStateSolid); 00686 G4Material *Cr = m->FindOrBuildMaterial("G4_Cr"); 00687 G4Material *Ni = m->FindOrBuildMaterial("G4_Ni"); 00688 G4Material *Mn = m->FindOrBuildMaterial("G4_Mn"); 00689 G4Material *Fe = m->FindOrBuildMaterial("G4_Fe"); 00690 v->AddMaterial(Cr,0.19); 00691 v->AddMaterial(Ni,0.10); 00692 v->AddMaterial(Mn,0.01); 00693 v->AddMaterial(Fe,0.70); 00694 return v; 00695 } 00696 if(materialName == "Stainless316") { 00697 // ignore optional components < 1% 00698 G4Material *v = new G4Material(materialName,8.01*g/cm3,5, 00699 kStateSolid); 00700 G4Material *Cr = m->FindOrBuildMaterial("G4_Cr"); 00701 G4Material *Ni = m->FindOrBuildMaterial("G4_Ni"); 00702 G4Material *Mn = m->FindOrBuildMaterial("G4_Mn"); 00703 G4Material *Mo = m->FindOrBuildMaterial("G4_Mo"); 00704 G4Material *Fe = m->FindOrBuildMaterial("G4_Fe"); 00705 v->AddMaterial(Cr,0.18); 00706 v->AddMaterial(Ni,0.12); 00707 v->AddMaterial(Mn,0.01); 00708 v->AddMaterial(Mo,0.025); 00709 v->AddMaterial(Fe,0.665); 00710 return v; 00711 } 00712 if(materialName == "lHe" || materialName == "LHe") { 00713 G4Material *v = new G4Material(materialName,0.1249*g/cm3,1, 00714 kStateLiquid); 00715 G4Material *He = m->FindOrBuildMaterial("G4_He"); 00716 v->AddMaterial(He,1.0); 00717 return v; 00718 } 00719 00720 // all materials in the database begin "G4_". 00721 if(materialName.find(G4) == 0) 00722 mat = m->FindOrBuildMaterial(materialName); 00723 else 00724 mat = m->FindOrBuildMaterial(G4+materialName); 00725 if(mat) return mat; 00726 if(!error) { 00727 printError("getMaterial: cannot find material '%s'", 00728 materialName.c_str()); 00729 return getMaterial("Vacuum"); 00730 } 00731 00732 G4Exception("getMaterial","Material not found",FatalException, 00733 materialName.c_str()); 00734 return 0; 00735 }
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(), BLCMDrfdevice::construct(), BLCMDpolycone::construct(), BLCMDparticlefilter::construct(), BLCMDmultipole::construct(), BLCMDlilens::construct(), BLCMDidealsectorbend::construct(), BLGroup::construct(), BLCMDgenericquad::construct(), BLCMDgenericbend::construct(), BLCMDextrusion::construct(), BLCMDcorner::construct(), BLCMDbox::construct(), BLCMDabsorber::construct(), and BLCMDfieldlines::generateOneFieldLine().
00738 { 00739 G4VisAttributes *p=0; 00740 00741 std::vector<G4double> v = getList(color,','); 00742 if(v.size() == 3) { 00743 p = new G4VisAttributes(true,G4Color(v[0],v[1],v[2])); 00744 } else if(v.size() == 4) { 00745 p = new G4VisAttributes(true,G4Color(v[0],v[1],v[2],v[3])); 00746 } else { 00747 p = new G4VisAttributes(G4VisAttributes::GetInvisible()); 00748 if(color.size() > 0 && toupper(color.c_str()[0]) != 'I') { 00749 printError("Invalid color '%s'",color.c_str()); 00750 } 00751 } 00752 00753 p->SetDaughtersInvisible(false); 00754 00755 return p; 00756 }
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. NOTE: This is expensive and should not be used during tracking.
References getDouble(), printError(), and splitString().
Referenced by BLCMDstart::command(), BLCMDreference::command(), BLCMDplace::command(), BLCMDcornerarc::command(), BLCMDcorner::command(), BLCMDbeam::command(), and BLCMDidealsectorbend::construct().
00759 { 00760 // We apply successive rotations OF THE OBJECT around the FIXED 00761 // axes of the parent's local coordinates; rotations are applied 00762 // left-to-right (rotation="r1,r2,r3" => apply r1 then r2 then r3). 00763 G4RotationMatrix *rot = new G4RotationMatrix(); 00764 std::vector<G4String> v = splitString(rotation,",",true); 00765 for(unsigned i=0; i<v.size(); ++i) { 00766 G4double angle=getDouble(v[i].substr(1)) * deg; 00767 if(gsl_isnan(angle)) { 00768 printError("Invalid rotation specification '%s'", 00769 rotation.c_str()); 00770 return 0; 00771 } 00772 G4RotationMatrix thisRotation; 00773 switch(v[i].c_str()[0]) { 00774 case 'X': case 'x': 00775 thisRotation = G4RotationMatrix(CLHEP::HepRotationX(angle)); 00776 break; 00777 case 'Y': case 'y': 00778 thisRotation = G4RotationMatrix(CLHEP::HepRotationY(angle)); 00779 break; 00780 case 'Z': case 'z': 00781 thisRotation = G4RotationMatrix(CLHEP::HepRotationZ(angle)); 00782 break; 00783 default: 00784 printError("Invalid rotation specification '%s'", 00785 rotation.c_str()); 00786 return 0; 00787 } 00788 *rot = thisRotation * *rot; 00789 } 00790 00791 return rot; 00792 }
void BLCommand::dumpRotation | ( | const G4RotationMatrix * | rot, | |
const char * | str | |||
) | [static] |
dumpRotation() dumps info about a rotation matrix to stdout. NOTE: This is expensive and should not be used during tracking.
Referenced by BLManager::displayGeometry().
00795 { 00796 if(!rot) { 00797 printf("%s: no rotation\n",str); 00798 return; 00799 } 00800 G4ThreeVector x(1.0,0.0,0.0), z(0.0,0.0,1.0); 00801 G4ThreeVector rx = *rot * x; 00802 G4ThreeVector rz = *rot * z; 00803 printf("%s: %.3f,%.3f,%.3f / %.3f,%.3f,%.3f / %.3f,%.3f,%.3f\n", 00804 str,rot->xx(),rot->xy(),rot->xz(),rot->yx(),rot->yy(),rot->yz(), 00805 rot->zx(),rot->zy(),rot->zz()); 00806 printf(" rot*x=%.3f,%.3f,%.3f rot*z = %.3f,%.3f,%.3f\n", 00807 rx[0],rx[1],rx[2],rz[0],rz[1],rz[2]); 00808 }
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. NOTE: This is expensive and should not be used during tracking.
Referenced by AsciiNTuple::AsciiNTuple(), SetDecayInstance::callback(), BLCMDtrackcuts::command(), BLCMDtotalenergy::command(), BLCMDphysics::command(), getList(), SetDecayInstance::isMatch(), BLCMDlist::listParticleDetails(), matchList(), MaterialFilter::MaterialFilter(), BLCMDparticlefilter::setup(), BLCMDextrusion::setup(), and stringToRotationMatrix().
00812 { 00813 G4String tmp(s), p; 00814 std::vector<G4String> v; 00815 while(tmp.size() > 0) { 00816 G4String::size_type i=tmp.find_first_of(delim); 00817 if(i > tmp.size()) i = tmp.size(); 00818 p = tmp.substr(0,i); 00819 if(trim) { 00820 while(p.size() > 0 && isspace(p.c_str()[0])) 00821 p.erase(0,1); 00822 while(p.size() > 0 && isspace(p.c_str()[p.size()-1])) 00823 p.erase(p.size()-1,1); 00824 } 00825 v.push_back(p); 00826 tmp.erase(0,i+1); 00827 } 00828 00829 return v; 00830 }
static double BLCommand::getDouble | ( | const G4String & | s | ) | [inline, static] |
getDouble() converts a string expression 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. NOTE: This is expensive and should not be used during tracking.
References BLEvaluator::evaluate().
Referenced by getList(), and stringToRotationMatrix().
00378 { 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. NOTE: This is expensive and should not be used during tracking.
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().
00834 { 00835 std::vector<G4String> vect_s = splitString(s,delim,true); 00836 std::vector<G4double> retval; 00837 00838 for(unsigned i=0; i<vect_s.size(); ++i) { 00839 G4double val=getDouble(vect_s[i]); 00840 if(gsl_isnan(val)) { 00841 retval.clear(); 00842 break; 00843 } 00844 retval.push_back(val); 00845 } 00846 00847 return retval; 00848 }
bool BLCommand::matchList | ( | const G4String | s, | |
const G4String | patternList | |||
) | [static] |
matchList() returns true if s matches any pattern in patternList, whch is a comma-separated list of file-glob patterns. NOTE: This is expensive and should not be used during tracking.
References fnmatch(), and splitString().
Referenced by BLCMDreweightprocess::isMatchingParticle(), and BLCMDreweightprocess::isMatchingProcess().
00851 { 00852 std::vector<G4String> v = splitString(patternList,",",false); 00853 for(unsigned i=0; i<v.size(); ++i) { 00854 if(fnmatch(v[i].c_str(),s.c_str(),0) == 0) 00855 return true; 00856 } 00857 00858 return false; 00859 }
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().