About Single instantiation Confuse while learning ExampleB1

In ExampleB1
the class runAction and eventAction and SteppingAction are new in the ActionInitialization.cpp Build()

eventAction and steppingAction need runAction as paramater.

The first question is runAction and eventAction and SteppingAction these is Single instantiation.
If the eventAction or SteppingAction is not, is there any where they are new or delete

I can’t construct the logical about these three class’s paramater passed.

thank you very much

The actions, that is the instances passed to the SetUserAction member functions, are ultimately owned and deleted by the underlying Geant4 manager classes, here:

  • G4VUserPrimaryGeneratorAction owned/deleted by G4RunManager
  • G4UserRunAction owned/deleted by G4RunManager
  • G4UserEventAction owned/deleted by G4EventManager
  • G4UserSteppingAction owned/deleted by G4TrackingManager

etc. In exampleB1, the pointers to the RunAction/EventAction are as you note, also passed to EventAction/SteppingAction, but these do not own these resources. They just store the pointer to access the “shared” resource here.

Note that Geant4 was designed before things like std::unique_ptr and std::shared_ptr were available so ownership semantics may not always be clear I’m afraid. There’s a gradual migration to use of proper RAII, but as this can change the APIs it’ll be a relatively long process given the stability demanded by our major stakeholders.

Thank you
I always thought it was these classed owned by ActionInitialization class
Now I have clearer understanding about the class of G4

When I run a g4 program, the programe will construct master RunAction(if I need) and construct runAction, eventAction, steppingAction of Child Thread(One ChildThread has one runAction,eventAction,steppingAction ) .
When the program start simulation. these classes are used by their management class. But these don’t be delete or new if the program not end.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.