Why are you adding a command for your stepping action to the physics list messenger? Does the command in that messenger class actually modify or set a flag data member in your stepping action?
Given that I simulate many events my supervisor asked to add the possibility to save or not data from the stepping action in the Root files (i.e. when I run to do the scoring mesh I don’t save data in the Root file).
Obviously i can just comment the linea in the stepping action, but my supervisor wants a “nice” program, so che asked me ti add a flag to enable or disabile the data from stepping action storming.
So che asked me to add a flag that I can command by the macro…so if the command in the macro is true I save data in Root file, otherwise if it is false I don’t store them.
To do it, my supervisor suggested me to define in the Physics list Messenger a boolean varieble then I tried to do it in the way that I showed in the first message, but I got errore during tue compiling…
Do you know how to fix it, or a simpler way to do it?
Write a messenger class for your stepping action. Make that class a data member of your stepping action, and pass a pointer to the stepping action object as an argument of the messenger class’s construction. Then in the messenger code where you trap the UI command, you can call a set function in your stepping action to set the flag.
The specific details of writing the code are left to you.
In the Geant4 examples/ directory, I find (find examples -name '*Messenger.cc') 294 examples you could choose from, all in the various extended/ and advanced/ examples (the basic/ examples do not include custom UI commands).
I suspect that looking at one of the StackingAction or RunAction Messenger examples might be most appropriate for your purposes. Maybe TestEm2?
Why are you trying to use the PhysicsListMessenger? That class is for the physics list. You should be writing your own separate Messenger class to use with your SteppingAction. Make that separate Messenger class a data member of your stepping action. Instantiate it in the SteppingAction construction, and pass a pointer to the SteppingAction into the separate Messenger class constructor, and store it in the Messenger as an unowned pointer.
It is up to you to write your own code to do what you want. Are you familiar with C++ in terms of design and philosophy? Not just copying and trying to modify code you don’t understand.
You still haven’t implemented any action to take when the user enters the macro command. Where is SetNewValue() defined and implemented in your SettingActionMessenger class? Please read the documentation.
Your SetNewValue() function definition, in particular the if block, is wrong. Did you look at any of the examples? Try looking at TestEm1/src/StepMaxMessenger.cc. Think about what the code is doing, don’t just copy and change letters.
Read the code to yourself out loud, and describe what it says it’s doing. Not what you want it to do. Then go look again at the example I pointed you toward. Read that code to yourself out loud, and describe what it says it’s doing. You should discover that what you have written is not what you intended, and not what works.
If you don’t know what the pointer operator (->) does in C++, or if you don’t know how to call functions with arguments, you will need to study basic C++ programming on your own.
When you call your SetRootFlag() function from the Messenger, you are passing in a string (look at the data type assigned to the newValues variable). When you wrote your SteppingAction class, you defined the SetRootFlag() function to take a bool as an argument. Obviously those are different.
The Messenger class provides functions which can automatically convert the input string to all the data types you might need. In this particular case, you’ll want to use StoB(newValues) (String toBool).