UI command UI command Makoto Asai (SLAC Computing Services) Makoto - - PowerPoint PPT Presentation

ui command ui command
SMART_READER_LITE
LIVE PREVIEW

UI command UI command Makoto Asai (SLAC Computing Services) Makoto - - PowerPoint PPT Presentation

UI command UI command Makoto Asai (SLAC Computing Services) Makoto Asai (SLAC Computing Services) Geant4 Tutorial Course @ Fermi Lab Geant4 Tutorial Course @ Fermi Lab th , 2003 October 27 th , 2003 October 27 Contents Contents Alias


slide-1
SLIDE 1

UI command UI command

Makoto Asai (SLAC Computing Services) Makoto Asai (SLAC Computing Services) Geant4 Tutorial Course @ Fermi Lab Geant4 Tutorial Course @ Fermi Lab October 27 October 27th

th, 2003

, 2003

slide-2
SLIDE 2

UI command UI command -

  • M.Asai (SLAC)

M.Asai (SLAC) -

  • Oct. 27, 2003 @ Fermi Lab
  • Oct. 27, 2003 @ Fermi Lab

2 2

Contents Contents

  • Alias and loop

Alias and loop

  • Mechanism of UI command

Mechanism of UI command

  • Messenger class

Messenger class

  • Defining a command

Defining a command

  • Implementing a messenger

Implementing a messenger

slide-3
SLIDE 3

UI command UI command -

  • M.Asai (SLAC)

M.Asai (SLAC) -

  • Oct. 27, 2003 @ Fermi Lab
  • Oct. 27, 2003 @ Fermi Lab

3 3

Alias Alias

  • Alias can be defined by

Alias can be defined by

/control/alias /control/alias [name] [value] [name] [value]

  • It is also set with

It is also set with /control/loop

/control/loop and

and /control/

/control/foreach foreach

commands commands

  • Aliased value is always treated as a string even if it contains

Aliased value is always treated as a string even if it contains only

  • nly

numbers. numbers.

  • Alias is to be used with other UI command.

Alias is to be used with other UI command.

  • Use curly brackets, { and } .

Use curly brackets, { and } .

  • For example, frequently used lengthy command can be shortened by

For example, frequently used lengthy command can be shortened by aliasing. aliasing.

/control/alias trv1 /control/alias trv1 " "/tracking/verbose 1 /tracking/verbose 1" " {trv1} {trv1}

  • Aliases can be used recursively.

Aliases can be used recursively.

/control/alias file1 / /control/alias file1 /diskA/dirX/fileXX.dat diskA/dirX/fileXX.dat /control/alias file2 / /control/alias file2 /diskB/dirY/fileYY.dat diskB/dirY/fileYY.dat /control/alias run 1 /control/alias run 1 / /myCmd/getFile myCmd/getFile { {file{run file{run}} }}

slide-4
SLIDE 4

UI command UI command -

  • M.Asai (SLAC)

M.Asai (SLAC) -

  • Oct. 27, 2003 @ Fermi Lab
  • Oct. 27, 2003 @ Fermi Lab

4 4

Loop Loop

  • /control/loop

/control/loop and

and /control/

/control/foreach foreach commands execute a macro

commands execute a macro file more than once. Aliased variable can be used inside the mac file more than once. Aliased variable can be used inside the macro file. ro file.

  • /control/loop [

/control/loop [macroFile macroFile] [ ] [counterName counterName] ] [ [initialValue initialValue] [ ] [finalValue finalValue] [ ] [stepSize stepSize] ]

  • counterName

counterName is aliased to the number as a loop counter

is aliased to the number as a loop counter

  • /control/

/control/foreach foreach [ [macroFile macroFile] [ ] [counterName counterName] [ ] [valueList valueList] ]

  • counterName

counterName is aliased to a value in

is aliased to a value in valueList

valueList

  • valueList

valueList must be enclosed by double quotes (" ")

must be enclosed by double quotes (" ")

  • n UI terminal or other macro file
  • n UI terminal or other macro file

/control/loop /control/loop myRun.mac myRun.mac Ekin Ekin 10. 20. 2.

  • 10. 20. 2.
  • in

in myRun.mac myRun.mac

/gun/energy { /gun/energy {Ekin Ekin} } GeV GeV /run/ /run/beamOn beamOn 100 100

slide-5
SLIDE 5

UI command UI command -

  • M.Asai (SLAC)

M.Asai (SLAC) -

  • Oct. 27, 2003 @ Fermi Lab
  • Oct. 27, 2003 @ Fermi Lab

5 5

Mechanism of UI command Mechanism of UI command

(G)UI G4UImanager messenger (G4UImessenger) command (G4UIcommand)

  • 1. register

command

  • 2. apply

Target class

  • 3. do it
  • 4. invoke

Object shown in green must be instantiated by the user Class shown in blue must be implemented and instantiated by the user

G4UIparameter

slide-6
SLIDE 6

UI command UI command -

  • M.Asai (SLAC)

M.Asai (SLAC) -

  • Oct. 27, 2003 @ Fermi Lab
  • Oct. 27, 2003 @ Fermi Lab

6 6

Messenger class Messenger class

  • Each messenger class must be derived from

Each messenger class must be derived from G4UImessenger G4UImessenger base class. base class. A messenger class can handle one or more UI commands. A messenger class can handle one or more UI commands.

  • A messenger class

A messenger class should be instantiated by should be instantiated by the constructor of the the constructor of the target target class class to which commands should be delivered, and to which commands should be delivered, and should be deleted should be deleted by by the destructor of the target class. the destructor of the target class.

  • Methods of messenger class

Methods of messenger class

  • Constructor

Constructor

  • Define (instantiate) commands / command directories

Define (instantiate) commands / command directories

  • Destructor

Destructor

  • Delete commands / command directories

Delete commands / command directories

  • void

void SetNewValue SetNewValue(G4UIcommand* command,G4String (G4UIcommand* command,G4String newValue newValue) )

  • Convert "

Convert "newValue newValue" parameter string to appropriate " parameter string to appropriate value(s value(s) and ) and invoke a method of the target class invoke a method of the target class

  • G4String

G4String GetCurrentValue GetCurrentValue(G4UIcommand* command) (G4UIcommand* command)

  • Access to a get

Access to a get-

  • method of the target class and convert the

method of the target class and convert the current values to a string current values to a string

slide-7
SLIDE 7

UI command UI command -

  • M.Asai (SLAC)

M.Asai (SLAC) -

  • Oct. 27, 2003 @ Fermi Lab
  • Oct. 27, 2003 @ Fermi Lab

7 7

Definition (instantiation) of a command Definition (instantiation) of a command

  • To be implemented in the constructor of a messenger class.

To be implemented in the constructor of a messenger class.

A01DetectorConstMessenger::A01DetectorConstMessenger A01DetectorConstMessenger::A01DetectorConstMessenger (A01DetectorConstruction* (A01DetectorConstruction* tgt tgt) ) : :target(tgt target(tgt) ) { { mydetDir mydetDir = new = new G4UIdirectory G4UIdirectory(" ("/mydet/ /mydet/"); "); mydetDir mydetDir-

  • >

>SetGuidance SetGuidance("A01 detector setup commands."); ("A01 detector setup commands."); armCmd armCmd = new = new G4UIcmdWithADoubleAndUnit G4UIcmdWithADoubleAndUnit(" ("/mydet/armAngle /mydet/armAngle",this); ",this); armCmd armCmd-

  • >

>SetGuidance SetGuidance("Rotation ("Rotation angle of the second arm."); angle of the second arm."); armCmd armCmd-

  • >

>SetParameterName SetParameterName("angle",true ("angle",true); ); armCmd armCmd-

  • >

>SetRange SetRange("angle ("angle>=0. && angle<180."); >=0. && angle<180."); armCmd armCmd-

  • >

>SetDefaultValue SetDefaultValue(30.); (30.); armCmd armCmd-

  • >

>SetDefaultUnit SetDefaultUnit("deg ("deg"); "); } }

  • Guidance can (should) be more than one lines. The first line is

Guidance can (should) be more than one lines. The first line is utilized utilized as a short description of the command. as a short description of the command.

slide-8
SLIDE 8

UI command UI command -

  • M.Asai (SLAC)

M.Asai (SLAC) -

  • Oct. 27, 2003 @ Fermi Lab
  • Oct. 27, 2003 @ Fermi Lab

8 8

G4UIcommand and its derivatives G4UIcommand and its derivatives

  • G4UIcommand

G4UIcommand is a class which represent a UI command. is a class which represent a UI command. G4UIparameter represents a parameter. G4UIparameter represents a parameter.

  • G4UIcommand can be directly used for a UI command. Geant4 provid

G4UIcommand can be directly used for a UI command. Geant4 provides es its derivatives according to the types of associated parameters. its derivatives according to the types of associated parameters.

  • G4UIcmdWithoutParameter

G4UIcmdWithoutParameter

  • G4UIcmdWithAString

G4UIcmdWithAString

  • G4UIcmdWithABool

G4UIcmdWithABool

  • G4UIcmdWithAnInteger

G4UIcmdWithAnInteger

  • G4UIcmdWithADouble, G4UIcmdWithADoubleAndUnit

G4UIcmdWithADouble, G4UIcmdWithADoubleAndUnit

  • G4UIcmdWith3Vector, G4UIcmdWith3VectorAndUnit

G4UIcmdWith3Vector, G4UIcmdWith3VectorAndUnit

  • G4UIdirectory

G4UIdirectory

  • A UI command with other type of parameters must be defined by

A UI command with other type of parameters must be defined by G4UIcommand base class. G4UIcommand base class.

slide-9
SLIDE 9

UI command UI command -

  • M.Asai (SLAC)

M.Asai (SLAC) -

  • Oct. 27, 2003 @ Fermi Lab
  • Oct. 27, 2003 @ Fermi Lab

9 9

Parameter Parameter name(s name(s) )

void void SetParameterName SetParameterName( ( const char* const char*parName parName, , G4bool G4bool omittable

  • mittable,

, G4bool G4bool currentAsDefault currentAsDefault=false); =false); void void SetParameterName SetParameterName( ( const char*nam1, const char*nam2, const char*nam3, const char*nam1, const char*nam2, const char*nam3, G4bool G4bool omittable

  • mittable,

, G4bool G4bool currentAsDefault currentAsDefault=false); =false);

  • Parameter names are used in held, and also in the definition of

Parameter names are used in held, and also in the definition of parameter range. parameter range.

  • If "

If "omittable

  • mittable" is true, the command can be issued without this particular

" is true, the command can be issued without this particular parameter value. parameter value.

  • If "

If "currentAsDefalult currentAsDefalult" is true, current value of the parameter is used as " is true, current value of the parameter is used as a default value, otherwise default value must be defined with a default value, otherwise default value must be defined with SetDefaultValue SetDefaultValue() method. () method.

slide-10
SLIDE 10

UI command UI command -

  • M.Asai (SLAC)

M.Asai (SLAC) -

  • Oct. 27, 2003 @ Fermi Lab
  • Oct. 27, 2003 @ Fermi Lab

10 10

Range, unit and candidates Range, unit and candidates

void void SetRange SetRange(const (const char* char* rangeString rangeString) )

  • Available for a command with numeric

Available for a command with numeric-

  • type parameters.

type parameters.

  • Range of

Range of parameter(s parameter(s) must be given in C+ + syntax. ) must be given in C+ + syntax.

aCmd aCmd-

  • >

>SetRange("x SetRange("x>0. && y>z && z>( >0. && y>z && z>(x+y x+y)"); )");

  • Not only comparison with hard

Not only comparison with hard-

  • coded number but also comparison

coded number but also comparison between variables and simple calculation are available. between variables and simple calculation are available.

  • Names of variables must be defined by

Names of variables must be defined by SetParameterName SetParameterName() method. () method.

void void SetDefaultUnit SetDefaultUnit(const (const char* char* defUnit defUnit) )

  • Available for a command which takes unit.

Available for a command which takes unit.

  • Once the default unit is defined, no other unit of different dim

Once the default unit is defined, no other unit of different dimension will ension will be accepted. be accepted.

  • Alternatively, you can define a dimension (unit category) withou

Alternatively, you can define a dimension (unit category) without setting t setting a default unit. a default unit.

void void SetUnitCategory(const SetUnitCategory(const char* char* unitCategory unitCategory) ) void void SetCandidates SetCandidates(const (const char* char* candidateList candidateList) )

  • Available for a command with string type parameter

Available for a command with string type parameter

  • Candidates must be delimited by a space.

Candidates must be delimited by a space.

  • candidates can be dynamically updated.

candidates can be dynamically updated.

slide-11
SLIDE 11

UI command UI command -

  • M.Asai (SLAC)

M.Asai (SLAC) -

  • Oct. 27, 2003 @ Fermi Lab
  • Oct. 27, 2003 @ Fermi Lab

11 11

Available state Available state

void void AvailableForStates AvailableForStates(G4ApplicationState s1,…) (G4ApplicationState s1,…)

  • Define command's applicability for Geant4

Define command's applicability for Geant4 application states. application states.

  • Geant4 has six application states.

Geant4 has six application states.

  • G4State_PreInit

G4State_PreInit

  • Material, Geometry, Particle and/or

Material, Geometry, Particle and/or Physics Process need to be initialized Physics Process need to be initialized

  • G4State_Idle

G4State_Idle

  • Ready to start a run

Ready to start a run

  • G4State_GeomClosed

G4State_GeomClosed

  • Geometry is optimized and ready to

Geometry is optimized and ready to process an event process an event

  • G4State_EventProc

G4State_EventProc

  • An event is processing

An event is processing

  • G4State_Quit, G4State_Abort

G4State_Quit, G4State_Abort

  • UI command unavailable

PreInit Idle EventProc GeomClosed Quit Abort

initialize beamOn exit

UI command unavailable

slide-12
SLIDE 12

UI command UI command -

  • M.Asai (SLAC)

M.Asai (SLAC) -

  • Oct. 27, 2003 @ Fermi Lab
  • Oct. 27, 2003 @ Fermi Lab

12 12

Converting between string and values Converting between string and values

  • Derivatives of G4UIcommand with numeric and

Derivatives of G4UIcommand with numeric and boolean boolean parameters have parameters have corresponding conversion methods. corresponding conversion methods.

  • From a string to value

From a string to value

G4bool G4bool GetNewBoolValue(const GetNewBoolValue(const char*) char*) G4int G4int GetNewIntValue(const GetNewIntValue(const char*) char*) G4double G4double GetNewDoubleValue(const GetNewDoubleValue(const char*) char*) G4ThreeVector GetNew3VectorValue(const char*) G4ThreeVector GetNew3VectorValue(const char*)

  • To be used in

To be used in SetNewValue SetNewValue() method in messenger. () method in messenger.

  • Unit is taken into account automatically.

Unit is taken into account automatically.

  • From value to string

From value to string

G4String G4String ConvertToString ConvertToString(...) (...) G4String G4String ConvertToString ConvertToString(...,const char* unit) (...,const char* unit)

  • To be used in

To be used in GetCurrentValue GetCurrentValue() method in messenger. () method in messenger.

slide-13
SLIDE 13

UI command UI command -

  • M.Asai (SLAC)

M.Asai (SLAC) -

  • Oct. 27, 2003 @ Fermi Lab
  • Oct. 27, 2003 @ Fermi Lab

13 13

SetNewValue SetNewValue and and GetCurrentValue GetCurrentValue

void A01DetectorConstMessenger void A01DetectorConstMessenger :: ::SetNewValue(G4UIcommand* command,G4String SetNewValue(G4UIcommand* command,G4String newValue newValue) ) { { if( command== if( command==armCmd armCmd ) ) { target { target-

  • >

>SetArmAngle(armCmd SetArmAngle(armCmd-

  • >

>GetNewDoubleValue GetNewDoubleValue(newValue (newValue)); } )); } } } G4String A01DetectorConstMessenger G4String A01DetectorConstMessenger :: ::GetCurrentValue(G4UIcommand* command) GetCurrentValue(G4UIcommand* command) { { G4String G4String cv cv; ; if( command== if( command==armCmd armCmd ) ) { { cv cv = = armCmd armCmd-

  • >

>ConvertToString ConvertToString(target (target-

  • >

>GetArmAngle(),"deg GetArmAngle(),"deg"); } "); } return return cv cv; ; } }