More on User Commands Makoto Asai SLAC Geant

  • Slides: 9
Download presentation
More on User Commands Makoto Asai (SLAC) Geant 4 Users Workshop @ CERN Nov.

More on User Commands Makoto Asai (SLAC) Geant 4 Users Workshop @ CERN Nov. 13 th, 2002 More on User Commands - M. Asai (SLAC) - Geant 4 Users Workshop @ CERN (Nov/13/2002)

Contents • • User-defined command User-defined messenger String stream object G 4 Exception. Handler

Contents • • User-defined command User-defined messenger String stream object G 4 Exception. Handler More on User Commands - M. Asai (SLAC) - Geant 4 Users Workshop @ CERN (Nov/13/2002) 2

UI command messenger (G)UI 2. apply G 4 UImessenger 1. register 3. do it

UI command messenger (G)UI 2. apply G 4 UImessenger 1. register 3. do it UImanager command 4. invoke Target class parameter More on User Commands - M. Asai (SLAC) - Geant 4 Users Workshop @ CERN (Nov/13/2002) 3

User command • To define user commands, you need to make your own concrete

User command • To define user commands, you need to make your own concrete messenger class implementation class G 4 Particle. Gun; class G 4 UIcmd. With. ADouble. And. Unit; #include "G 4 UImessenger. hh" class G 4 Particle. Gun. Messenger: public G 4 UImessenger { public: G 4 Particle. Gun. Messenger(G 4 Particle. Gun * f. Ptcl. Gun); ~G 4 Particle. Gun. Messenger(); void Set. New. Value(G 4 UIcommand * command, G 4 String new. Values); G 4 String Get. Current. Value(G 4 UIcommand * command); private: G 4 Particle. Gun * f. Particle. Gun; G 4 UIcmd. With. ADouble. And. Unit * energy. Cmd; }; More on User Commands - M. Asai (SLAC) - Geant 4 Users Workshop @ CERN (Nov/13/2002) 4

Messenger class • Constructor – Instantiate command objects, set guidance, parameter information, etc. ,

Messenger class • Constructor – Instantiate command objects, set guidance, parameter information, etc. , and register commands to UImanager. • Destructor – Delete commands (automatically unregistered). • Set. New. Value method – Convert parameter string to values – Invoke appropriate method of the target class object • Get. Current. Value method – Get current values from the target class object – Convert them to string and return the string More on User Commands - M. Asai (SLAC) - Geant 4 Users Workshop @ CERN (Nov/13/2002) 5

Command classes • G 4 UIcommand – Base class, Still usable for complicated command

Command classes • G 4 UIcommand – Base class, Still usable for complicated command • G 4 UIdirectory – Definition of (sub-)directory • G 4 UIcmd. With 3 Vector, G 4 UIcmd. With 3 Vector. And. Unit, G 4 UIcmd. With. ADouble. And. Unit, G 4 UIcmd. With. AString, G 4 UIcmd. With. ABool, G 4 UIcmd. With. An. Integer, G 4 UIcmd. Without. Parameter – Each class has its adequate conversion methods between a string and values. • Application state(s), for which a command is valid, can be set. More on User Commands - M. Asai (SLAC) - Geant 4 Users Workshop @ CERN (Nov/13/2002) 6

Parameter • Each parameter must have its unique name (within a command) • If

Parameter • Each parameter must have its unique name (within a command) • If a parameter is set as “omittable”, default value must be given, or “current value as default” flag must be set. • Range(s) of parameter(s) can be given by C++ syntax. – E. g. “x>=0. && y>= 0. && x > y” • Candidate list is a string consists of candidates separated by spaces. direction. Cmd = new G 4 UIcmd. With 3 Vector("/gun/direction", this); direction. Cmd->Set_guidance("Set momentum direction. "); direction. Cmd ->Set_guidance("Direction needs not to be a unit vector. "); direction. Cmd->Set. Parameter. Name("Px", "Py", "Pz", true); direction. Cmd->Set. Range("Px != 0 || Py != 0 || Pz != 0"); • See section 7. 2 of User's Guide For Application Developers for more detail and full example code. More on User Commands - M. Asai (SLAC) - Geant 4 Users Workshop @ CERN (Nov/13/2002) 7

String stream objects • G 4 cout and G 4 cerr are objects of

String stream objects • G 4 cout and G 4 cerr are objects of ostream and they have G 4 strstreambuf buffer objects. • Strings are sent to G 4 UIsession concrete class for handling appropriate to a (G)UI. – G 4 UIsession is the base class of all (G)UIs or interfaces to GUIs. This base class has methods Receive. G 4 cout and Receive. G 4 cerr to receive strings. • To connect Geant 4 to an external framework, the user must implement an interface concrete class derived from G 4 UIsession, so that the external framework can receive G 4 cout/G 4 cerr strings. More on User Commands - M. Asai (SLAC) - Geant 4 Users Workshop @ CERN (Nov/13/2002) 8

G 4 Exception. Handler • Geant 4 provides G 4 VException. Handler base class,

G 4 Exception. Handler • Geant 4 provides G 4 VException. Handler base class, which is “notified” once G 4 Exception occurs. – Geant 4 provides G 4 Exception. Handler concrete class for the “default” behavior of core dump. – Once the user implements and instantiates his/her own concrete class, it automatically overwrites the default behavior. • We are planning to enrich error messages and also to provide more flexible severities of exceptions. – At least for exceptions which are most likely user oriented. More on User Commands - M. Asai (SLAC) - Geant 4 Users Workshop @ CERN (Nov/13/2002) 9