1 / 9

User-defined commands and messengers in Geant4

Learn how to define custom commands and messengers in Geant4 for enhanced control and interaction. Explore the implementation of user-defined concrete messenger classes and their functionality.

moneal
Download Presentation

User-defined commands and messengers in Geant4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. More on User Commands Makoto Asai (SLAC) Geant4 Users Workshop @ CERN Nov. 13th, 2002

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

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

  4. User command • To define user commands, you need to make your own concrete messenger class implementation class G4ParticleGun; class G4UIcmdWithADoubleAndUnit; #include "G4UImessenger.hh" class G4ParticleGunMessenger: public G4UImessenger { public: G4ParticleGunMessenger(G4ParticleGun * fPtclGun); ~G4ParticleGunMessenger(); void SetNewValue(G4UIcommand * command,G4String newValues); G4String GetCurrentValue(G4UIcommand * command); private: G4ParticleGun * fParticleGun; G4UIcmdWithADoubleAndUnit * energyCmd; }; More on User Commands - M.Asai (SLAC) - Geant4 Users Workshop @ CERN (Nov/13/2002)

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

  6. Command classes • G4UIcommand • Base class, Still usable for complicated command • G4UIdirectory • Definition of (sub-)directory • G4UIcmdWith3Vector, G4UIcmdWith3VectorAndUnit, G4UIcmdWithADouble, G4UIcmdWithADoubleAndUnit, G4UIcmdWithAString, G4UIcmdWithABool, G4UIcmdWithAnInteger, G4UIcmdWithoutParameter • 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) - Geant4 Users Workshop @ CERN (Nov/13/2002)

  7. 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. directionCmd = new G4UIcmdWith3Vector("/gun/direction",this); directionCmd->Set_guidance("Set momentum direction."); directionCmd ->Set_guidance("Direction needs not to be a unit vector."); directionCmd->SetParameterName("Px","Py","Pz",true,true); directionCmd->SetRange("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) - Geant4 Users Workshop @ CERN (Nov/13/2002)

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

  9. G4ExceptionHandler • Geant4 provides G4VExceptionHandler base class, which is “notified” once G4Exception occurs. • Geant4 provides G4ExceptionHandler 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) - Geant4 Users Workshop @ CERN (Nov/13/2002)

More Related