Logo ROOT   6.18/05
Reference Guide
TMCManager.h
Go to the documentation of this file.
1// @(#)root/vmc:$Id$
2// Authors: Benedikt Volkel 07/03/2019
3
4/*************************************************************************
5 * Copyright (C) 2019, Rene Brun and Fons Rademakers. *
6 * Copyright (C) 2019, ALICE Experiment at CERN. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#ifndef ROOT_TMCManager
14#define ROOT_TMCManager
15//
16// Class TMCManager
17// ---------------------------
18// manager class for handling multiple TVirtualMC engines.
19//
20
21#include <functional>
22#include <memory>
23
24#include "TMCtls.h"
26#include "TMCParticleStatus.h"
27#include "TGeoManager.h"
28#include "TVirtualMC.h"
29
30class TVirtualMC;
32class TParticle;
33class TVirtualMCStack;
34class TMCManagerStack;
35
37
39
40public:
41 /// Default constructor
42 TMCManager();
43
44 /// Destructor
45 virtual ~TMCManager();
46
47 /// Static access method
48 static TMCManager *Instance();
49
50 //
51 // Methods to manage multiple engines
52 //
53
54 /// A TVirtualMC will register itself via this method during construction
55 /// if a TMCManager was instanciated before.
56 /// The TMCManager will assign an ID to the engines.
57 void Register(TVirtualMC *engine);
58
59 /// The user application will register itself via this method when the
60 /// manager was requested.
61 void Register(TVirtualMCApplication *application);
62
63 /// Return the number of registered engines.
64 Int_t NEngines() const;
65
66 /// Get registered engine pointers
67 void GetEngines(std::vector<TVirtualMC *> &engines) const;
68
69 /// Get an engine pointer by ID
70 TVirtualMC *GetEngine(Int_t id) const;
71
72 /// Get engine ID by its name
73 Int_t GetEngineId(const char *name) const;
74
75 /// Get the current engine pointer
77
78 /// Connect a pointer which is updated whenever the engine is changed
80
81 /// Connect a pointer which is updated whenever the engine is changed
83
84 //
85 // Stack related methods
86 //
87
88 /// Set user stack
89 void SetUserStack(TVirtualMCStack *stack);
90
91 /// User interface to forward particle to specifiic engine.
92 /// It is assumed that the TParticle is owned by the user. It will not be
93 /// modified by the TMCManager.
94 void ForwardTrack(Int_t toBeDone, Int_t trackId, Int_t parentId, TParticle *particle, Int_t engineId);
95
96 /// User interface to forward particle to specifiic engine.
97 /// It is assumed that the TParticle is owned by the user. It will not be
98 /// modified by the TMCManager.
99 /// Assume current engine Id
100 void ForwardTrack(Int_t toBeDone, Int_t trackId, Int_t parentId, TParticle *particle);
101
102 /// Transfer track from current engine to engine with engineTargetId
103 void TransferTrack(Int_t engineTargetId);
104
105 /// Transfer track from current engine to target engine mc
106 void TransferTrack(TVirtualMC *mc);
107
108 /// Try to restore geometry for a given track
109 Bool_t RestoreGeometryState(Int_t trackId, Bool_t checkTrackIdRange = kTRUE);
110
111 /// Try to restore geometry for the track currently set
113
114 //
115 // Steering and control
116 //
117
118 /// Apply something to all engines
119 template <typename F>
120 void Apply(F engineLambda)
121 {
122 for (auto &mc : fEngines) {
123 // We never know whether static method TVirtualMC::GetMC() is used in any way so update before calling the
124 // lambda.
126 engineLambda(mc);
127 }
128 }
129
130 /// Initialize engines
131 void Init();
132 /// Further specific initialization
133 template <typename F>
134 void Init(F initFunction)
135 {
136 if (fIsInitializedUser) {
137 return;
138 }
139 Init();
140 for (auto &mc : fEngines) {
141 // Set to current engine and call user init procedure
143 initFunction(mc);
144 }
146 }
147
148 /// Run the event loop
149 void Run(Int_t nEvents);
150
151private:
152 /// Do necessary steps before an event is triggered
153 void PrepareNewEvent();
154 /// Find the next engine
156 /// Update all engine pointers connected to the TMCManager
158 /// Terminate a run in all engines
159 void TerminateRun();
160
161private:
162 // static data members
163#if !defined(__CINT__)
164 static TMCThreadLocal TMCManager *fgInstance; ///< Singleton instance
165#else
166 static TMCManager *fgInstance; ///< Singleton instance
167#endif
168
169 /// Pointer to user application
171 /// Pointer to current engine
173 /// Collecting pointers to all instanciated TVirtualMCs
174 std::vector<TVirtualMC *> fEngines;
175 /// Stacks connected to engines
176 std::vector<std::unique_ptr<TMCManagerStack>> fStacks;
177 /// All tracks (persistent)
178 std::vector<TParticle *> fParticles;
179 /// All particles' status (persistent)
180 std::vector<std::unique_ptr<TMCParticleStatus>> fParticlesStatus;
181 /// Total number of primaries ever pushed
183 /// Total number of tracks ever pushed
185 /// Connected engine pointers which will be updated everytime the current
186 /// engine changes
187 std::vector<TVirtualMC **> fConnectedEnginePointers;
188 /// Pointer to user stack
190 /// Pointer to cache with geometry states
192 /// Flag if engines are initilaized
194 /// Flag if specific initialization for engines was done
196
198};
199
200#endif
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassDef(name, id)
Definition: Rtypes.h:326
char name[80]
Definition: TGX11.cxx:109
#define TMCThreadLocal
Definition: TMCtls.h:80
Storing and re-using geometry states of the TGeoManager in use by storing them as TGeoBranchArrays.
Concrete implementation of particles stack used by the TMCManager.
Singleton manager class for handling and steering a run with multiple TVirtualMC engines sharing even...
Definition: TMCManager.h:36
Int_t GetEngineId(const char *name) const
Get engine ID by its name.
Definition: TMCManager.cxx:173
Bool_t RestoreGeometryState()
Try to restore geometry for the track currently set.
Definition: TMCManager.cxx:354
TVirtualMC * GetCurrentEngine() const
Get the current engine pointer.
Definition: TMCManager.cxx:189
void TerminateRun()
Terminate a run in all engines.
Definition: TMCManager.cxx:495
virtual ~TMCManager()
Destructor.
Definition: TMCManager.cxx:61
void ForwardTrack(Int_t toBeDone, Int_t trackId, Int_t parentId, TParticle *particle, Int_t engineId)
User interface to forward particle to specifiic engine.
Definition: TMCManager.cxx:234
std::vector< TParticle * > fParticles
All tracks (persistent)
Definition: TMCManager.h:178
std::vector< TVirtualMC ** > fConnectedEnginePointers
Connected engine pointers which will be updated everytime the current engine changes.
Definition: TMCManager.h:187
Int_t fTotalNPrimaries
Total number of primaries ever pushed.
Definition: TMCManager.h:182
void ConnectEnginePointer(TVirtualMC **mc)
Connect a pointer which is updated whenever the engine is changed.
Definition: TMCManager.cxx:199
void TransferTrack(Int_t engineTargetId)
Transfer track from current engine to engine with engineTargetId.
Definition: TMCManager.cxx:280
Bool_t GetNextEngine()
Find the next engine.
Definition: TMCManager.cxx:462
TVirtualMC * fCurrentEngine
Pointer to current engine.
Definition: TMCManager.h:172
TVirtualMC * GetEngine(Int_t id) const
Get an engine pointer by ID.
Definition: TMCManager.cxx:160
void UpdateEnginePointers(TVirtualMC *mc)
Update all engine pointers connected to the TMCManager.
Definition: TMCManager.cxx:480
void Apply(F engineLambda)
Apply something to all engines.
Definition: TMCManager.h:120
void Init()
Initialize engines.
Definition: TMCManager.cxx:364
Bool_t fIsInitializedUser
Flag if specific initialization for engines was done.
Definition: TMCManager.h:195
TVirtualMCApplication * fApplication
Pointer to user application.
Definition: TMCManager.h:170
void PrepareNewEvent()
Do necessary steps before an event is triggered.
Definition: TMCManager.cxx:440
std::vector< std::unique_ptr< TMCManagerStack > > fStacks
Stacks connected to engines.
Definition: TMCManager.h:176
TVirtualMCStack * fUserStack
Pointer to user stack.
Definition: TMCManager.h:189
static TMCThreadLocal TMCManager * fgInstance
Singleton instance.
Definition: TMCManager.h:164
static TMCManager * Instance()
Static access method.
Definition: TMCManager.cxx:74
Int_t fTotalNTracks
Total number of tracks ever pushed.
Definition: TMCManager.h:184
TMCManager()
Default constructor.
Definition: TMCManager.cxx:46
std::vector< std::unique_ptr< TMCParticleStatus > > fParticlesStatus
All particles' status (persistent)
Definition: TMCManager.h:180
void Run(Int_t nEvents)
Run the event loop.
Definition: TMCManager.cxx:408
std::vector< TVirtualMC * > fEngines
Collecting pointers to all instanciated TVirtualMCs.
Definition: TMCManager.h:174
Bool_t fIsInitialized
Flag if engines are initilaized.
Definition: TMCManager.h:193
void SetUserStack(TVirtualMCStack *stack)
Set user stack.
Definition: TMCManager.cxx:222
Int_t NEngines() const
Return the number of registered engines.
Definition: TMCManager.cxx:136
void Init(F initFunction)
Further specific initialization.
Definition: TMCManager.h:134
TGeoMCBranchArrayContainer fBranchArrayContainer
Pointer to cache with geometry states.
Definition: TMCManager.h:191
void Register(TVirtualMC *engine)
A TVirtualMC will register itself via this method during construction if a TMCManager was instanciate...
Definition: TMCManager.cxx:86
void GetEngines(std::vector< TVirtualMC * > &engines) const
Get registered engine pointers.
Definition: TMCManager.cxx:146
Description of the dynamic properties of a particle.
Definition: TParticle.h:26
Interface to a user Monte Carlo application.
Interface to a user defined particles stack.
Abstract Monte Carlo interface.
Definition: TVirtualMC.h:42
#define F(x, y, z)