VMC Version 2.0
Loading...
Searching...
No Matches
TMCManager.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------
2// Copyright (C) 2019 CERN and copyright holders of VMC Project.
3// This software is distributed under the terms of the GNU General Public
4// License v3 (GPL Version 3), copied verbatim in the file "LICENSE".
5//
6// See https://github.com/vmc-project/vmc for full licensing information.
7// -----------------------------------------------------------------------
8
9// Authors: Benedikt Volkel 07/03/2019
10
11/*************************************************************************
12 * Copyright (C) 2019, Rene Brun and Fons Rademakers. *
13 * Copyright (C) 2019, ALICE Experiment at CERN. *
14 * All rights reserved. *
15 * *
16 * For the licensing terms see $ROOTSYS/LICENSE. *
17 * For the list of contributors see $ROOTSYS/README/CREDITS. *
18 *************************************************************************/
19
20#ifndef ROOT_TMCManager
21#define ROOT_TMCManager
22//
23// Class TMCManager
24// ---------------------------
25// manager class for handling multiple TVirtualMC engines.
26//
27
28#include <functional>
29#include <memory>
30
31#include "TMCtls.h"
33#include "TMCParticleStatus.h"
34#include "TGeoManager.h"
35#include "TVirtualMC.h"
36
37class TVirtualMC;
39class TParticle;
40class TVirtualMCStack;
41class TMCManagerStack;
42
44
46
47public:
49 TMCManager();
50
52 virtual ~TMCManager();
53
55 static TMCManager *Instance();
56
57 //
58 // Methods to manage multiple engines
59 //
60
64 void Register(TVirtualMC *engine);
65
68 void Register(TVirtualMCApplication *application);
69
71 Int_t NEngines() const;
72
74 void GetEngines(std::vector<TVirtualMC *> &engines) const;
75
77 TVirtualMC *GetEngine(Int_t id) const;
78
80 Int_t GetEngineId(const char *name) const;
81
84
87
90
91 //
92 // Stack related methods
93 //
94
96 void SetUserStack(TVirtualMCStack *stack);
97
101 void ForwardTrack(Int_t toBeDone, Int_t trackId, Int_t parentId, TParticle *particle, Int_t engineId);
102
107 void ForwardTrack(Int_t toBeDone, Int_t trackId, Int_t parentId, TParticle *particle);
108
110 void TransferTrack(Int_t engineTargetId);
111
113 void TransferTrack(TVirtualMC *mc);
114
116 Bool_t RestoreGeometryState(Int_t trackId, Bool_t checkTrackIdRange = kTRUE);
117
119 Bool_t RestoreGeometryState();
120
121 //
122 // Steering and control
123 //
124
126 template <typename F>
127 void Apply(F engineLambda)
128 {
129 for (auto &mc : fEngines) {
130 // We never know whether static method TVirtualMC::GetMC() is used in any way so update before calling the
131 // lambda.
133 engineLambda(mc);
134 }
135 }
136
138 void Init();
140 template <typename F>
141 void Init(F initFunction)
142 {
143 if (fIsInitializedUser) {
144 return;
145 }
146 Init();
147 for (auto &mc : fEngines) {
148 // Set to current engine and call user init procedure
150 initFunction(mc);
151 }
152 fIsInitializedUser = kTRUE;
153 }
154
156 void Run(Int_t nEvents);
157
158private:
160 void PrepareNewEvent();
162 Bool_t GetNextEngine();
166 void TerminateRun();
167
168private:
169 // static data members
170#if !defined(__CINT__)
171 static TMCThreadLocal TMCManager *fgInstance;
172#else
173 static TMCManager *fgInstance;
174#endif
175
181 std::vector<TVirtualMC *> fEngines;
183 std::vector<std::unique_ptr<TMCManagerStack>> fStacks;
185 std::vector<TParticle *> fParticles;
187 std::vector<std::unique_ptr<TMCParticleStatus>> fParticlesStatus;
194 std::vector<TVirtualMC **> fConnectedEnginePointers;
204
205 ClassDef(TMCManager, 0)
206};
207
208#endif
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:43
Int_t GetEngineId(const char *name) const
Get engine ID by its name.
Definition: TMCManager.cxx:183
Bool_t RestoreGeometryState()
Try to restore geometry for the track currently set.
Definition: TMCManager.cxx:364
TVirtualMC * GetCurrentEngine() const
Get the current engine pointer.
Definition: TMCManager.cxx:199
Bool_t fGeometryConstructed
Definition: TMCManager.h:203
void TerminateRun()
Terminate a run in all engines.
Definition: TMCManager.cxx:505
virtual ~TMCManager()
Destructor.
Definition: TMCManager.cxx:68
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:244
std::vector< TParticle * > fParticles
All tracks (persistent)
Definition: TMCManager.h:185
std::vector< TVirtualMC ** > fConnectedEnginePointers
Connected engine pointers which will be updated everytime the current engine changes.
Definition: TMCManager.h:194
Int_t fTotalNPrimaries
Total number of primaries ever pushed.
Definition: TMCManager.h:189
void ConnectEnginePointer(TVirtualMC **mc)
Connect a pointer which is updated whenever the engine is changed.
Definition: TMCManager.cxx:209
void TransferTrack(Int_t engineTargetId)
Transfer track from current engine to engine with engineTargetId.
Definition: TMCManager.cxx:290
Bool_t GetNextEngine()
Find the next engine.
Definition: TMCManager.cxx:472
TVirtualMC * fCurrentEngine
Pointer to current engine.
Definition: TMCManager.h:179
TVirtualMC * GetEngine(Int_t id) const
Get an engine pointer by ID.
Definition: TMCManager.cxx:170
void UpdateEnginePointers(TVirtualMC *mc)
Update all engine pointers connected to the TMCManager.
Definition: TMCManager.cxx:490
void Apply(F engineLambda)
Apply something to all engines.
Definition: TMCManager.h:127
void Init()
Initialize engines.
Definition: TMCManager.cxx:374
Bool_t fIsInitializedUser
Flag if specific initialization for engines was done.
Definition: TMCManager.h:202
TVirtualMCApplication * fApplication
Pointer to user application.
Definition: TMCManager.h:177
void PrepareNewEvent()
Do necessary steps before an event is triggered.
Definition: TMCManager.cxx:450
std::vector< std::unique_ptr< TMCManagerStack > > fStacks
Stacks connected to engines.
Definition: TMCManager.h:183
TVirtualMCStack * fUserStack
Pointer to user stack.
Definition: TMCManager.h:196
static TMCThreadLocal TMCManager * fgInstance
Singleton instance.
Definition: TMCManager.h:171
static TMCManager * Instance()
Static access method.
Definition: TMCManager.cxx:81
Int_t fTotalNTracks
Total number of tracks ever pushed.
Definition: TMCManager.h:191
TMCManager()
Default constructor.
Definition: TMCManager.cxx:53
std::vector< std::unique_ptr< TMCParticleStatus > > fParticlesStatus
All particles' status (persistent)
Definition: TMCManager.h:187
void Run(Int_t nEvents)
Run the event loop.
Definition: TMCManager.cxx:418
std::vector< TVirtualMC * > fEngines
Collecting pointers to all instanciated TVirtualMCs.
Definition: TMCManager.h:181
Bool_t fIsInitialized
Flag if engines are initilaized.
Definition: TMCManager.h:200
void SetUserStack(TVirtualMCStack *stack)
Set user stack.
Definition: TMCManager.cxx:232
Int_t NEngines() const
Return the number of registered engines.
Definition: TMCManager.cxx:146
void Init(F initFunction)
Further specific initialization.
Definition: TMCManager.h:141
TGeoMCBranchArrayContainer fBranchArrayContainer
Pointer to cache with geometry states.
Definition: TMCManager.h:198
void Register(TVirtualMC *engine)
A TVirtualMC will register itself via this method during construction if a TMCManager was instanciate...
Definition: TMCManager.cxx:93
void GetEngines(std::vector< TVirtualMC * > &engines) const
Get registered engine pointers.
Definition: TMCManager.cxx:156
Interface to a user Monte Carlo application.
Interface to a user defined particles stack.
Abstract Monte Carlo interface.
Definition: TVirtualMC.h:49