Adding your own commands (p_ex2)
Often, you want to be able to influence the processing while the loop is running, for example:
- set flags to enable/disable parts of your code (“do hits but not tracks”), general steering
- book/enable sets of histograms and have them filled on the fly
- set parameter values (such as pedestal values) which are used by the process loop
It’s easy to get carried away here - often it’s better to start a second root process to do what you want than to get all the mechanics in place to make that configurable. Judgement call.
Remember that all your (usually 2) threads share the same memory space. One thread sets a value, the other one can see it without additional hassle.
It’s just a matter of getting access to the variable in question.
For just a few, global variables will do.
If you want more fancy control and maybe a state machine, a singleton object will be better.
Easier to write down than to tell here abstractly.
In the p_ex2 example, we have two histograms. We want to be able to suspend their filling individually, and also be able to learn if they are “switched off” or not. We do that with global variables..