BLCommand Class Reference

#include <BLCommand.hh>

Inheritance diagram for BLCommand:

BLCMDbeam BLCMDbeamlossntuple BLCMDbug1021 BLCMDcoil BLCMDcollective BLCMDcornerarc BLCMDcosmicraybeam BLCMDdefine BLCMDdemo BLCMDdo BLCMDendgroup BLCMDeventcuts BLCMDexit BLCMDfieldntuple BLCMDg4ui BLCMDgeometry BLCMDhelp BLCMDif BLCMDinclude BLCMDlist BLCMDmaterial BLCMDmovie BLCMDmuminuscapturefix BLCMDnewparticlentuple BLCMDntuple BLCMDoutput BLCMDparam BLCMDparticlecolor BLCMDparticlesource BLCMDphysics BLCMDplace BLCMDprintf BLCMDprintfield BLCMDprobefield BLCMDprofile BLCMDrandomseed BLCMDreference BLCMDsetdecay BLCMDshowmaterial BLCMDstart BLCMDtest BLCMDtimentuple BLCMDtotalenergy BLCMDtrace BLCMDtrackcuts BLCMDtracker BLCMDtrackermode BLCMDtune BLCMDzntuple BLCommandAlias BLElement Macro

List of all members.


Detailed Description

class BLCommand - interface to define a command.

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


Member Enumeration Documentation

enum BLCommand::TokenType [private]

Enumerator:
NONE 
ARGNAME 
ARGVALUE 
00092 { NONE, ARGNAME, ARGVALUE };

enum BLCommand::ArgumentMode [protected]

Enumerator:
PROCESS 
COUNT 
HELP 
PRINT 
CHANGE 
00105 { PROCESS, COUNT, HELP, PRINT, CHANGE };


Constructor & Destructor Documentation

BLCommand::BLCommand (  )  [inline, protected]

Default Constructor.

00120                     : synopsis(), description()
00121                 { }

BLCommand::~BLCommand (  )  [protected, virtual]

Destructor.

00052 {
00053 }

BLCommand::BLCommand ( const BLCommand r  )  [inline, protected]

Copy Constructor.

00127                                       : synopsis(), description()
00128                 { }


Member Function Documentation

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

00488 {
00489         // (add +- for particlecolor pi+=1,1,1)
00490         static const char namechars[] = ",+-ABCDEFGHIJKLMNOPQRSTUVWXYZ_"
00491                                        "abcdefghijklmnopqrstuvwxyz0123456789";
00492         G4String::size_type i;
00493 
00494         // check if previous token was ARGNAME
00495         if(line[place] == '=') {
00496                 ++place;
00497                 goto value;
00498         }
00499 
00500         // skip initial whitespace
00501         while(place < line.size() && isspace(line[place])) ++place;
00502 
00503         // check for ARGNAME
00504         if(isalnum(line[place]) || line[place] == '_') {
00505                 i = line.find_first_not_of(namechars,place);
00506                 if(i > place && i < line.size() && line[i] == '=' &&
00507                                                         line[i+1] != '=') {
00508                         G4String retval = line.substr(place,i-place);
00509                         place = i;
00510                         type = ARGNAME;
00511                         return retval;
00512                 }
00513         }
00514 value:
00515         if(line[place] == '"') {
00516                 ++place;
00517                 i = line.find('"',place);
00518                 if(i <line.size()) {
00519                         G4String retval = line.substr(place,i-place);
00520                         place = i + 1;
00521                         type = ARGVALUE;
00522                         return retval;
00523                 }
00524         } else if(line[place] == '\'') {
00525                 ++place;
00526                 i = line.find('\'',place);
00527                 if(i <line.size()) {
00528                         G4String retval = line.substr(place,i-place);
00529                         place = i + 1;
00530                         type = ARGVALUE;
00531                         return retval;
00532                 }
00533         }
00534 
00535         if(place >= line.size()) {
00536                 type = NONE;
00537                 return "";
00538         }
00539 
00540         // find next whitespace
00541         G4String::size_type start = place;
00542         while(place < line.size() && !isspace(line[place])) ++place;
00543 
00544         type = ARGVALUE;
00545 
00546         return line.substr(start,place-start);
00547 }

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

00315 {
00316         G4String indent1(IndentDesc);
00317         indent1 += name;
00318         do { indent1 += " "; } while(indent1.size() < IndentArg.size());
00319         printf("%s",wrapWords(_description,indent1,IndentArg).c_str());
00320 }

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(), BLCMDfieldmap::BLCMDfieldmap(), BLCMDfieldntuple::BLCMDfieldntuple(), BLCMDg4ui::BLCMDg4ui(), BLCMDgenericbend::BLCMDgenericbend(), BLCMDgenericquad::BLCMDgenericquad(), BLCMDgeometry::BLCMDgeometry(), BLCMDhelicaldipole::BLCMDhelicaldipole(), 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(), 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().

00056 {
00057         type = _type;
00058 
00059         if(!mapCommand)
00060                 mapCommand = new std::map<G4String,BLCommand*>;
00061         if((*mapCommand).count(commandName()) > 0 &&
00062            (*mapCommand)[commandName()] != this)
00063                 printError("Attempt to re-define the command '%s'",
00064                                 commandName().c_str());
00065         else
00066                 (*mapCommand)[commandName()] = this;
00067 }

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(), BLCMDfieldmap::BLCMDfieldmap(), BLCMDfieldntuple::BLCMDfieldntuple(), BLCMDg4ui::BLCMDg4ui(), BLCMDgenericbend::BLCMDgenericbend(), BLCMDgenericquad::BLCMDgenericquad(), BLCMDgeometry::BLCMDgeometry(), BLCMDhelicaldipole::BLCMDhelicaldipole(), 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(), 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(), BLCMDfieldmap::BLCMDfieldmap(), BLCMDfieldntuple::BLCMDfieldntuple(), BLCMDg4ui::BLCMDg4ui(), BLCMDgenericbend::BLCMDgenericbend(), BLCMDgenericquad::BLCMDgenericquad(), BLCMDgeometry::BLCMDgeometry(), BLCMDhelicaldipole::BLCMDhelicaldipole(), 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(), 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(), BLCMDfieldexpr::defineNamedArgs(), BLCMDextrusion::defineNamedArgs(), BLCMDeventcuts::defineNamedArgs(), BLCMDdemo::defineNamedArgs(), BLCMDcornerarc::defineNamedArgs(), BLCMDcorner::defineNamedArgs(), BLCMDcoil::defineNamedArgs(), BLCMDbox::defineNamedArgs(), BLCMDbeamlossntuple::defineNamedArgs(), BLCMDbeam::defineNamedArgs(), and BLCMDabsorber::defineNamedArgs().

00133 {
00134         switch(argMode) {
00135         case CHANGE:
00136                 if(!permitChange) {
00137                         if(argName == name)
00138                                 printError("%s: Argument '%s' is not permitted to change\n",
00139                                         commandName().c_str(),name.c_str());
00140                         break;
00141                 }
00142                 // flow into PROCESS
00143         case PROCESS:   
00144                 if(argFound || argName != name) return;
00145                 argFound = true;
00146                 var = argValue;
00147                 break;
00148         case COUNT:
00149                 ++nArgs;
00150                 if(!permitChange) ++nFixed;
00151                 break;
00152         case HELP:      
00153                 printArgDesc(name,_description+(permitChange?"":" #"));
00154                 break;
00155         case PRINT:
00156                 printArgString += name;
00157                 printArgString += "=";
00158                 printArgString += var;
00159                 printArgString += "\n";
00160                 break;
00161         }
00162 }

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(), 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(), BLCMDhelicaldipole::defineNamedArgs(), BLGroup::defineNamedArgs(), BLCMDgeometry::defineNamedArgs(), BLCMDgenericquad::defineNamedArgs(), BLCMDgenericbend::defineNamedArgs(), BLCMDfieldmap::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().

00166 {
00167         if(fmt == "") fmt = DefaultDoubleFmt;
00168 
00169         switch(argMode) {
00170         case CHANGE:
00171                 if(!permitChange) {
00172                         if(argName == name)
00173                                 printError("%s: Argument '%s' is not permitted to change\n",
00174                                         commandName().c_str(),name.c_str());
00175                         break;
00176                 }
00177                 // flow into PROCESS
00178         case PROCESS:   
00179                 if(argFound || argName != name) return;
00180                 argFound = true;
00181                 { BLEvaluator e;
00182                   G4double v = e.evaluate(argValue);
00183                   if(e.status() != HepTool::Evaluator::OK) {
00184                           printError("Invalid value for argument '%s'"
00185                                 " to command '%s'", argName.c_str(),
00186                                 commandName().c_str());
00187                           return;
00188                   }
00189                   var = v * units;
00190                 }
00191 /**** 
00192                 { const char *p=argValue.c_str();
00193                   char *q;
00194                   G4double v = strtod(p,&q);
00195                   if(p == q || *q != '\0') {
00196                         printError("Invalid value for argument '%s'"
00197                                 " to command '%s'", argName.c_str(),
00198                                 commandName().c_str());
00199                         return;
00200                   }
00201                   var = v * units;
00202                 }
00203 ****/
00204                 break;
00205         case COUNT:
00206                 ++nArgs;
00207                 if(!permitChange) ++nFixed;
00208                 break;
00209         case HELP:      
00210                 printArgDesc(name,_description+(permitChange?"":" #"));
00211                 break;
00212         case PRINT:
00213                 { char tmp[65];
00214                   snprintf(tmp,sizeof(tmp),fmt.c_str(),var/units);
00215                   printArgString += name;
00216                   printArgString += "=";
00217                   printArgString += tmp;
00218                   printArgString += "\n";
00219                 }
00220                 break;
00221         }
00222 }

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

00226 {
00227         if(fmt == "") fmt = DefaultDoubleFmt;
00228 
00229         switch(argMode) {
00230         case CHANGE:
00231         case PROCESS:   
00232                 if(argFound || argName != name) return;
00233                 argFound = true;
00234                 BLTune::defineTunableArg(var,units,argValue);
00235                 break;
00236         case HELP:      
00237                 printArgDesc(name,_description+" @");
00238                 break;
00239         case COUNT:
00240                 ++nArgs;
00241                 ++nTunable;
00242                 break;
00243         case PRINT:
00244                 { char tmp[65];
00245                   snprintf(tmp,sizeof(tmp),fmt.c_str(),var/units);
00246                   printArgString += name;
00247                   printArgString += "=";
00248                   printArgString += tmp;
00249                   printArgString += "\n";
00250                 }
00251                 break;
00252         }
00253 }

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(), BLCMDsolenoid::defineNamedArgs(), BLCMDreference::defineNamedArgs(), BLCMDprintfield::defineNamedArgs(), BLCMDpolycone::defineNamedArgs(), BLCMDplace::defineNamedArgs(), BLCMDpillbox::defineNamedArgs(), BLCMDphysics::defineNamedArgs(), BLCMDparticlesource::defineNamedArgs(), BLCMDparticlefilter::defineNamedArgs(), BLCMDntuple::defineNamedArgs(), BLCMDmultipole::defineNamedArgs(), BLCMDidealsectorbend::defineNamedArgs(), BLCMDgeometry::defineNamedArgs(), BLCMDgenericquad::defineNamedArgs(), BLCMDgenericbend::defineNamedArgs(), BLCMDg4ui::defineNamedArgs(), BLCMDfieldntuple::defineNamedArgs(), BLCMDfieldexpr::defineNamedArgs(), BLCMDextrusion::defineNamedArgs(), BLCMDcosmicraybeam::defineNamedArgs(), BLCMDcollective::defineNamedArgs(), BLCMDcoil::defineNamedArgs(), BLCMDbox::defineNamedArgs(), and BLCMDbeam::defineNamedArgs().

00257 {
00258         switch(argMode) {
00259         case CHANGE:
00260                 if(!permitChange) {
00261                         if(argName == name)
00262                                 printError("%s: Argument '%s' is not permitted to change\n",
00263                                         commandName().c_str(),name.c_str());
00264                         break;
00265                 }
00266                 // flow into PROCESS
00267         case PROCESS:   
00268                 if(argFound || argName != name) return;
00269                 argFound = true;
00270                 { BLEvaluator e;
00271                   G4double v = e.evaluate(argValue);
00272                   var = (G4int)(v+0.5);
00273                   if(e.status() != HepTool::Evaluator::OK ||
00274                                                         fabs(var-v) > 0.001) {
00275                           printError("Invalid value for argument '%s'"
00276                                 " to command '%s'", argName.c_str(),
00277                                 commandName().c_str());
00278                           return;
00279                   }
00280                 }
00281 /***
00282                 { const char *p=argValue.c_str();
00283                   char *q;
00284                   G4int v = strtol(p,&q,0);
00285                   if(p == q || *q != '\0') {
00286                         printError("Invalid value for argument '%s'"
00287                                 " to command '%s'", argName.c_str(),
00288                                 commandName().c_str());
00289                         return;
00290                   }
00291                   var = v;
00292                 }
00293 ***/
00294                 break;
00295         case COUNT:
00296                 ++nArgs;
00297                 if(!permitChange) ++nFixed;
00298                 break;
00299         case HELP:      
00300                 printArgDesc(name,_description+(permitChange?"":" #"));
00301                 break;
00302         case PRINT:
00303                 { char tmp[65];
00304                   snprintf(tmp,sizeof(tmp),"%d",var);
00305                   printArgString += name;
00306                   printArgString += "=";
00307                   printArgString += tmp;
00308                   printArgString += "\n";
00309                 }
00310                 break;
00311         }
00312 }

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(), 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(), BLCMDhelicaldipole::command(), BLGroup::command(), BLCMDgeometry::command(), BLCMDgenericquad::command(), BLCMDgenericbend::command(), BLCMDg4ui::command(), BLCMDfieldntuple::command(), BLCMDfieldmap::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().

00323 {
00324         int retval = 0;
00325         argMode = PROCESS;
00326 
00327         BLArgumentMap::iterator i;
00328         for(i=args.begin(); i!=args.end(); ++i) {
00329                 argName = i->first;
00330                 argValue = i->second;
00331                 argFound = false;
00332                 defineNamedArgs();
00333                 if(!argFound) { 
00334                         printError("Invalid argument '%s' to command '%s'",
00335                                 argName.c_str(),commandName().c_str());
00336                         retval = -1;
00337                 }
00338         }
00339 
00340         if(args.size() > 0) argChanged();
00341 
00342         return retval;
00343 }

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

00351 {
00352         G4String str(commandName());
00353         do { str += " "; } while(str.size() < IndentDesc.size());
00354         printf("%s%s\n",str.c_str(),synopsis.c_str());
00355         if(detailed) {
00356                 if(description.rfind(": ") == description.size()-2)
00357                         description += BLNTuple::getFormatList(); 
00358                 printf("\n%s",wrapWords(description,IndentDesc,IndentDesc).c_str());
00359                 nArgs = nFixed = nTunable = 0;
00360                 argMode = COUNT;
00361                 defineNamedArgs();
00362                 if(nArgs > 0) {
00363                         printf("\n%sNamed Arguments", IndentDesc.c_str());
00364                         if(nFixed > 0) 
00365                                 printf(" (#=cannot be changed in place cmd)");
00366                         if(nTunable > 0) printf(" (@=Tunable)");
00367                         printf(":\n");
00368                         argMode = HELP;
00369                         defineNamedArgs();
00370                 }
00371         }
00372 }

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

00081 {
00082         G4String retval(""), space(" "), line(""), word("");
00083         G4String::size_type pos=0, next=0;
00084         bool eol=false;
00085 
00086         while(pos < text.size()) {
00087                 if(eol && isspace(text[pos])) {
00088                         next = text.find_first_of("\n",pos);
00089                         if(next == text.npos) next = text.size();
00090                         if(line.size() > 0) {retval += line; retval += "\n";}
00091                         line = indent + text.substr(pos,next-pos);
00092                         retval += line;
00093                         retval += "\n";
00094                         line = "";
00095                         pos = next + 1;
00096                         // eol = true;
00097                         continue;
00098                 }
00099                 next = text.find_first_of(" \t\r\n",pos);
00100                 if(next == text.npos) {
00101                         word = text.substr(pos);
00102                         next = text.size();
00103                 } else {
00104                         word = text.substr(pos,next-pos);
00105                         eol = (text[next] == '\n');
00106                 }
00107                 if(word.size() > 0) {
00108                         if(line.size() == 0) {
00109                                 if(retval.size() == 0)
00110                                         line = indent1;
00111                                 else
00112                                         line = indent;
00113                                 line += word;
00114                         } else if(line.size()+word.size()+1 < width) {
00115                                 line += space;
00116                                 line += word;
00117                         } else {
00118                                 retval += line;
00119                                 retval += "\n";
00120                                 line = indent;
00121                                 line += word;
00122                         } 
00123                 }
00124                 pos = next + 1;
00125         } 
00126         if(line.size() > 0) {retval += line; retval += "\n";}
00127 
00128         return retval;
00129 }

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

00375 {
00376         printArgString = "";
00377         argMode = PRINT;
00378         defineNamedArgs();
00379         printf("%s",wrapWords(printArgString,indent1,IndentArg).c_str());
00380 }

virtual G4String BLCommand::commandName (  )  [pure virtual]

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, BLCMDfieldmap, BLCMDfieldntuple, BLCMDg4ui, BLCMDgenericbend, BLCMDgenericquad, BLCMDgeometry, BLCMDhelicaldipole, 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, 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]

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

00265 { }

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(), 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(), BLCMDhelicaldipole::command(), BLGroup::command(), BLCMDgeometry::command(), BLCMDgenericquad::command(), BLCMDgenericbend::command(), BLCMDg4ui::command(), BLCMDfieldmap::command(), BLCMDfieldexpr::command(), BLCMDextrusion::command(), BLCMDeventcuts::command(), BLCMDcornerarc::command(), BLCMDcorner::command(), BLCMDcollective::command(), BLCMDbug1021::command(), BLCMDbox::command(), BLCMDbeamlossntuple::command(), and BLCMDabsorber::command().

00383 {
00384         G4String indent1(commandName());
00385         do { indent1 += " "; } while(indent1.size() < IndentDesc.size());
00386         indent1 += name;
00387         do { indent1 += " "; } while(indent1.size() < IndentArg.size());
00388         printArgs(indent1);
00389 }

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

00392 {
00393         G4String indent1(commandName());
00394         do { indent1 += " "; } while(indent1.size() < IndentDesc.size());
00395         indent1 += name;
00396         do { indent1 += " "; } while(indent1.size() < IndentArg.size());
00397         printArgString = "";
00398         BLArgumentMap::iterator i;
00399         for(i=namedArgs.begin(); i!=namedArgs.end(); ++i) {
00400                 printArgString += i->first;
00401                 printArgString += "=";
00402                 printArgString += i->second;
00403                 printArgString += "\n";
00404         }
00405         printf("%s",wrapWords(printArgString,indent1,IndentArg).c_str());
00406 }

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.

00281 { return "??"; }

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

00409 {
00410         BLArgumentVector argv;
00411         BLArgumentMap namedArgs;
00412         G4String::size_type place = 0;
00413         TokenType type;
00414 
00415         if(line.size() < 1) return 0;
00416         char c = line.c_str()[0];
00417         if(c == '#') return 0;
00418         if(c == '*') {
00419                 printf("%s\n",line.c_str());
00420                 return 0;
00421         }
00422         if(c == '!') {
00423                 printf("%s\n",line.c_str());
00424                 fflush(stdout);
00425                 system(line.c_str()+1);
00426                 return 0;
00427         }
00428         if(c == '/') {
00429                 printf("%s\n",line.c_str());
00430                 G4UImanager* UI = G4UImanager::GetUIpointer();
00431                 UI->ApplyCommand(line.c_str());
00432                 return 0;
00433         }
00434 
00435         G4String cmd = nextToken(line,place,type);
00436         switch(type) {
00437         case NONE:
00438                 return 0;       // line with only whitespace
00439         case ARGVALUE:
00440                 break;
00441         case ARGNAME:
00442                 printError("Syntax Error");
00443                 return -1;
00444         }
00445 
00446         if(parseArgs(line.substr(place),argv,namedArgs) < 0)
00447                 return -1;
00448 
00449         int retval;
00450         if((*mapCommand).count(cmd) > 0) {
00451                 retval = (*mapCommand)[cmd]->command(argv,namedArgs);
00452         } else {
00453                 retval = -1;
00454                 printError("Unknown command '%s'",cmd.c_str());
00455         }
00456 
00457         return retval;
00458 }

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

00462 {
00463         G4String::size_type place = 0;
00464         while(place < line.size()) {
00465                 TokenType type;
00466                 G4String arg = nextToken(line,place,type), val;
00467                 switch(type) {
00468                 case NONE:
00469                         break;
00470                 case ARGNAME:
00471                         val = nextToken(line,place,type);
00472                         if(type != ARGVALUE) {
00473                                 printError("Syntax Error");
00474                                 return -1;
00475                         }
00476                         namedArgs[arg] = Param.expand(val);
00477                         break;
00478                 case ARGVALUE:
00479                         argv.push_back(Param.expand(arg));
00480                         break;
00481                 }
00482         }
00483         return 0;
00484 }

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

00550 {
00551         std::istream *save = in;
00552 
00553         std::ifstream fin;
00554         if(filename == "-") {
00555                 in = &std::cin;
00556         } else {
00557 #ifdef WIN32
00558                 fin.open(filename.c_str(),fin.in|fin.binary);
00559 #else
00560                 fin.open(filename.c_str());
00561 #endif
00562                 in = &fin;
00563         }
00564         if(in == 0 || !in->good()) {
00565                 printError("Cannot open file '%s'",filename.c_str());
00566                 return -1;
00567         }
00568 
00569         int errorCount = getErrorCount();
00570 
00571         while(in->good()) {
00572                 G4String *line = getNextCommand();
00573                 if(!line || line->find("exit") == 0) break;
00574                 doCommand(*line);
00575         }
00576 
00577         fin.close();
00578         if(in == &std::cin) std::cout << std::endl;
00579 
00580         in = save;
00581         return getErrorCount() - errorCount;
00582 }

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(), 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(), BLCMDhelicaldipole::command(), BLGroup::command(), BLCMDgenericquad::command(), BLCMDgenericbend::command(), BLCMDg4ui::command(), BLCMDfieldntuple::command(), BLCMDfieldmap::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(), DataCards::fetchValueDouble(), DataCards::fetchValueString(), FOR009NTuple::FOR009NTuple(), GenericBendField::GenericBendField(), GenericQuadField::GenericQuadField(), BLCoordinates::getCoordinateType(), BLParam::getInt(), getMaterial(), BLParam::getString(), getVisAttrib(), GridImpl::handleCommand(), handleNamedArgs(), BLCMDplace::handleNamedArgs(), BLCMDtracker::handlePreviousTracks(), BLCMDlist::listParticleDetails(), BLCMDfieldntuple::Loop::Loop(), MultipoleField::MultipoleField(), BLCMDtrace::newTrace(), parseArgs(), BLGroup::placeElement(), BLFieldMap::readFile(), readFile(), BLCoil::readMapFile(), registerCommand(), CylinderImpl::setField(), GridImpl::setField(), setPos(), BLCMDpolycone::setup(), BLCMDextrusion::setup(), BLCMDntuple::setupFirstEvent(), stringToRotationMatrix(), TrackerPlaneInstance::TrackerPlaneInstance(), BLTune::update(), and BLCMDprofile::Entry::UserZSteppingAction().

00070 {
00071         va_list ap;
00072         va_start(ap,fmt);
00073         fprintf(stdout,"***");
00074         vfprintf(stdout,fmt,ap);
00075         fprintf(stdout,"\n");
00076         ++errors;
00077 }

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.

Referenced by BLCMDif::command(), BLCMDexit::command(), BLCMDdo::command(), and readFile().

00585 {
00586         static G4String line;
00587 
00588         if(in == &std::cin) std::cout << "cmd: ";
00589 
00590         char tmp[1024+1];
00591 
00592         do {
00593                 if(!in->good()) return 0;
00594                 in->getline(tmp,sizeof(tmp));
00595                 if(strchr(tmp,'\r')) *strchr(tmp,'\r') = '\0';
00596                 line = tmp;
00597         } while(line.size() == 0);
00598 
00599         // handle continuation lines (ending with \)
00600         while(line[line.size()-1] == '\\' && in->good()) {
00601                 line[line.size()-1] = ' ';
00602                 in->getline(tmp,sizeof(tmp));
00603                 if(strchr(tmp,'\r')) *strchr(tmp,'\r') = '\0';
00604                 line += tmp;
00605         }
00606 
00607         // trim whitespace
00608         G4String::size_type i = line.find_first_not_of(" \t\r\n\v");
00609         if(i == line.npos) i = line.size();
00610         line.erase(0,i);
00611         while((i=line.find_last_of(" \t\r\n\v")) != line.npos) {
00612                 if(i != line.size()-1) break;
00613                 line.erase(i);
00614         }
00615 
00616         return &line;
00617 }

BLCommandPos BLCommand::getPos (  )  [static]

getPos() returns the current position of the Command input stream

References in.

Referenced by BLCMDdo::command().

00620 {
00621         BLCommandPos pos(in);
00622         return pos;
00623 }

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

00626 {
00627         if(in != pos.in) {
00628                 printError("Invalid BLCommand setPos()");
00629                 return;
00630         }
00631 
00632         in->seekg(pos.pos);
00633 }

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

00636 {
00637         const G4String G4("G4_");
00638         G4NistManager *m = G4NistManager::Instance();
00639 
00640         // first, check if it has already been constructed
00641         G4Material *mat = G4Material::GetMaterial(materialName,false);
00642         if(mat) return mat;
00643         mat = G4Material::GetMaterial(G4+materialName,false);
00644         if(mat) return mat;
00645 
00646         // Check for alias
00647         // NOTE: these materials are also listed in BLCMDmaterial::help()
00648         if(materialName == "Air") materialName = "AIR";
00649         if(materialName == "H2O") materialName = "WATER";
00650         if(materialName == "LH2") materialName = "lH2";
00651         if(materialName == "Vacuum") {
00652                 // preserve the name "Vacuum" 
00653                 G4Material *g = m->FindOrBuildMaterial("G4_Galactic");
00654                 G4Material *v = new G4Material(materialName,
00655                         g->GetDensity(),1,g->GetState(),g->GetTemperature(),
00656                         g->GetPressure());
00657                 v->AddMaterial(g,1.0);
00658                 return v;
00659         }
00660         if(materialName == "Scintillator") {
00661                 // preserve the name "Scintillator" 
00662                 G4Material *g = m->FindOrBuildMaterial("G4_POLYSTYRENE");
00663                 G4Material *v = new G4Material(materialName,
00664                         g->GetDensity(),1,g->GetState(),g->GetTemperature(),
00665                         g->GetPressure());
00666                 v->AddMaterial(g,1.0);
00667                 return v;
00668         }
00669         if(materialName == "Stainless304") {
00670                 // ignore optional components < 1%
00671                 G4Material *v = new G4Material(materialName,8.01*g/cm3,4,
00672                         kStateSolid);
00673                 G4Material *Cr = m->FindOrBuildMaterial("G4_Cr");
00674                 G4Material *Ni = m->FindOrBuildMaterial("G4_Ni");
00675                 G4Material *Mn = m->FindOrBuildMaterial("G4_Mn");
00676                 G4Material *Fe = m->FindOrBuildMaterial("G4_Fe");
00677                 v->AddMaterial(Cr,0.19);
00678                 v->AddMaterial(Ni,0.10);
00679                 v->AddMaterial(Mn,0.01);
00680                 v->AddMaterial(Fe,0.70);
00681                 return v;
00682         }
00683         if(materialName == "Stainless316") {
00684                 // ignore optional components < 1%
00685                 G4Material *v = new G4Material(materialName,8.01*g/cm3,5,
00686                         kStateSolid);
00687                 G4Material *Cr = m->FindOrBuildMaterial("G4_Cr");
00688                 G4Material *Ni = m->FindOrBuildMaterial("G4_Ni");
00689                 G4Material *Mn = m->FindOrBuildMaterial("G4_Mn");
00690                 G4Material *Mo = m->FindOrBuildMaterial("G4_Mo");
00691                 G4Material *Fe = m->FindOrBuildMaterial("G4_Fe");
00692                 v->AddMaterial(Cr,0.18);
00693                 v->AddMaterial(Ni,0.12);
00694                 v->AddMaterial(Mn,0.01);
00695                 v->AddMaterial(Mo,0.025);
00696                 v->AddMaterial(Fe,0.665);
00697                 return v;
00698         }
00699         if(materialName == "lHe" || materialName == "LHe") {
00700                 G4Material *v = new G4Material(materialName,0.1249*g/cm3,1,
00701                         kStateLiquid);
00702                 G4Material *He = m->FindOrBuildMaterial("G4_He");
00703                 v->AddMaterial(He,1.0);
00704                 return v;
00705         }
00706 
00707         // all materials in the database begin "G4_".
00708         if(materialName.find(G4) == 0)
00709                 mat = m->FindOrBuildMaterial(materialName);
00710         else
00711                 mat = m->FindOrBuildMaterial(G4+materialName);
00712         if(mat) return mat;
00713         if(!error) {
00714                 printError("getMaterial: cannot find material '%s'",
00715                                                 materialName.c_str());
00716                 return getMaterial("Vacuum");
00717         }
00718 
00719         G4Exception("getMaterial","Material not found",FatalException,
00720                                                         materialName.c_str());
00721         return 0;
00722 }

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(), and BLCMDabsorber::construct().

00725 {
00726         G4VisAttributes *p=0;
00727 
00728         std::vector<G4double> v = getList(color,',');
00729         if(v.size() == 3) {
00730                 p = new G4VisAttributes(true,G4Color(v[0],v[1],v[2]));
00731         } else {
00732                 p = new G4VisAttributes(G4VisAttributes::GetInvisible());
00733                 if(color.size() > 0 && toupper(color.c_str()[0]) != 'I') {
00734                         printError("Invalid color '%s'",color.c_str());
00735                 }
00736         }
00737 
00738         p->SetDaughtersInvisible(false);
00739 
00740         return p;
00741 }

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

00744 {
00745         // We apply successive rotations OF THE OBJECT around the FIXED
00746         // axes of the parent's local coordinates; rotations are applied
00747         // left-to-right (rotation="r1,r2,r3" => apply r1 then r2 then r3).
00748         G4RotationMatrix *rot = new G4RotationMatrix();
00749         std::vector<G4String> v = splitString(rotation,",",true);
00750         for(unsigned i=0; i<v.size(); ++i) {
00751                 G4double angle=getDouble(v[i].substr(1)) * deg;
00752                 if(gsl_isnan(angle)) {
00753                         printError("Invalid rotation specification '%s'",
00754                                                 rotation.c_str());
00755                         return 0;
00756                 }
00757                 G4RotationMatrix thisRotation;
00758                 switch(v[i].c_str()[0]) {
00759                 case 'X': case 'x':
00760                         thisRotation = G4RotationMatrix(CLHEP::HepRotationX(angle));
00761                         break;
00762                 case 'Y': case 'y':
00763                         thisRotation = G4RotationMatrix(CLHEP::HepRotationY(angle));
00764                         break;
00765                 case 'Z': case 'z':
00766                         thisRotation = G4RotationMatrix(CLHEP::HepRotationZ(angle));
00767                         break;
00768                 default:
00769                         printError("Invalid rotation specification '%s'",
00770                                                 rotation.c_str());
00771                         return 0;
00772                 }
00773                 *rot = thisRotation * *rot;
00774         }
00775 
00776         return rot;
00777 }

void BLCommand::dumpRotation ( const G4RotationMatrix *  rot,
const char *  str 
) [static]

dumpRotation() dumps info about a rotation matrix to stdout.

Referenced by BLManager::displayGeometry().

00780 {
00781         if(!rot) {
00782                 printf("%s: no rotation\n",str);
00783                 return;
00784         }
00785         G4ThreeVector x(1.0,0.0,0.0), z(0.0,0.0,1.0);
00786         G4ThreeVector rx = *rot * x;
00787         G4ThreeVector rz = *rot * z;
00788         printf("%s: %.3f,%.3f,%.3f / %.3f,%.3f,%.3f / %.3f,%.3f,%.3f\n",
00789                 str,rot->xx(),rot->xy(),rot->xz(),rot->yx(),rot->yy(),rot->yz(),
00790                 rot->zx(),rot->zy(),rot->zz());
00791         printf("        rot*x=%.3f,%.3f,%.3f   rot*z = %.3f,%.3f,%.3f\n",
00792                 rx[0],rx[1],rx[2],rz[0],rz[1],rz[2]);
00793 }

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

00797 {
00798         G4String tmp(s), p;
00799         std::vector<G4String> v;
00800         while(tmp.size() > 0) {
00801                 G4String::size_type i=tmp.find_first_of(delim);
00802                 if(i > tmp.size()) i = tmp.size();
00803                 p = tmp.substr(0,i);
00804                 if(trim) {
00805                         while(p.size() > 0 && isspace(p.c_str()[0]))
00806                                 p.erase(0,1);
00807                         while(p.size() > 0 && isspace(p.c_str()[p.size()-1]))
00808                                 p.erase(p.size()-1,1);
00809                 }
00810                 v.push_back(p);
00811                 tmp.erase(0,i+1);
00812         }
00813 
00814         return v;
00815 }

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(), GenericBendField::GenericBendField(), GenericQuadField::GenericQuadField(), getVisAttrib(), BLCMDfieldntuple::Loop::Loop(), BLCMDpolycone::setup(), and BLCMDextrusion::setup().

00819 {
00820         std::vector<G4String> vect_s = splitString(s,delim,true);
00821         std::vector<G4double> retval;
00822 
00823         for(unsigned i=0; i<vect_s.size(); ++i) {
00824                 G4double val=getDouble(vect_s[i]);
00825                 if(gsl_isnan(val)) {
00826                         retval.clear();
00827                         break;
00828                 }
00829                 retval.push_back(val);
00830         }
00831 
00832         return retval;
00833 }


Friends And Related Function Documentation

friend class BLCMDplace [friend]

friend class BLCMDhelp [friend]


Member Data Documentation

std::map< G4String, BLCommand * > * BLCommand::mapCommand [static, private]

int BLCommand::errors = 0 [static, private]

Referenced by getErrorCount(), and printError().

std::istream * BLCommand::in = 0 [static, private]

bool BLCommand::argFound [protected]

G4String BLCommand::argName [protected]

G4String BLCommand::argValue [protected]

G4String BLCommand::synopsis [protected]

Referenced by help(), and setSynopsis().

G4String BLCommand::description [protected]

G4String BLCommand::printArgString [protected]

int BLCommand::nArgs [protected]

int BLCommand::nFixed [protected]

Referenced by argDouble(), argInt(), argString(), and help().

int BLCommand::nTunable [protected]

Referenced by argTunable(), and help().


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