Message: Re: GetCurrentValue of G4UIcommand Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Idea Re: GetCurrentValue of G4UIcommand 

Forum: Analysis
Re: Question GetCurrentValue of G4UIcommand (Zhiyi Liu)
Date: 15 Jan, 2016
From: Michael H. Kelsey <Michael H. Kelsey>

On Fri, 15 Jan 2016 03:27:25 GMT, Zhiyi Liu wrote:
> Hi,
> I am using a messenger to read parameters from a macro file. The doc
> that I am referring to is:
> In my messenger code, I defined several commands using
> G4UIcmdWithADouble. In order to print what I set in my macro file, I try
> to print the commands and its parameter in the function,
> SetNewValue(...) by using:
>   //print command
>   std::cout << command->GetCommandPath()
>    << " "
>    << command->GetCurrentValue()
>    << " #" << command->GetGuidanceLine(0)
>    << std::endl;
> However, it is weird to notice that only the current value of the 1st
> command defined in the constructor of the messenger is properly printed,
> other commands defined afterwards have an empty "current value" string.
> I suspect this is a bug of GetCurrentValue(), please confirm.

I suspect it may be a "bug" in your G4UIMessenger class. If you are making use of the Messenger's built in "StoD()" or other string conversion functions, then there is no way for the underlying G4UIcommand objects to know that the string is associated with them. If you properly call command->GetNewDoubleValue(string); within your Messenger, then the G4UIcommand object should set its internal "current value" correctly.

For example:

  void MyMessenger::SetNewValue(G4UIcommand* cmd, G4String val) {
    if (cmd == cmd1) [do-something-with](cmd1->GetNewDoubleValue(val));
    if (cmd == cmd2) [do-something-with](cmd2->GetNewDoubleValue(val));

etc. On the other hand, if you take the short cut

  void MyMessenger::SetNewValue(G4UIcommand* cmd, G4String val) {
    if (cmd == cmd1) [do-something-with](StoD(val));
    if (cmd == cmd2) [do-something-with](StoD(val));

etc., then you aren't telling the commands that the input value (val) belongs to them.

I know this seems weird, since presumably the parser has already figured out which cmdX pointer was used, and could have already associated val to it. But it doesn't.

 Add Message Add Message
to: "Re: GetCurrentValue of G4UIcommand"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]