Logo ROOT   6.19/01
Reference Guide
TVirtualMCApplication.cxx
Go to the documentation of this file.
1 // @(#)root/vmc:$Id$
2 // Author: Ivana Hrivnacova, 27/03/2002
3 
4 /*************************************************************************
5  * Copyright (C) 2006, Rene Brun and Fons Rademakers. *
6  * Copyright (C) 2002, 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 #include "TVirtualMCApplication.h"
14 #include "TError.h"
15 #include "TVirtualMC.h"
16 #include "TMCManager.h"
17 
18 /** \class TVirtualMCApplication
19  \ingroup vmc
20 
21 Interface to a user Monte Carlo application.
22 
23 */
24 
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 ///
30 /// Standard constructor
31 ///
32 
33 TVirtualMCApplication::TVirtualMCApplication(const char *name, const char *title) : TNamed(name, title)
34 {
35  if (fgInstance) {
36  ::Fatal("TVirtualMCApplication::TVirtualMCApplication", "Attempt to create two instances of singleton.");
37  }
38 
39  // This is set to true if a TMCManager was reuqested.
40  if (fLockMultiThreading) {
41  ::Fatal("TVirtualMCApplication::TVirtualMCApplication", "In multi-engine run ==> multithreading is disabled.");
42  }
43 
44  fgInstance = this;
45  // There cannot be a TVirtualMC since it must have registered to this
46  // TVirtualMCApplication
47  fMC = nullptr;
48  fMCManager = nullptr;
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 ///
53 /// Default constructor
54 ///
55 
57 {
58  fgInstance = this;
59  fMC = nullptr;
60  fMCManager = nullptr;
61 }
62 
63 ////////////////////////////////////////////////////////////////////////////////
64 ///
65 /// Destructor
66 ///
67 
69 {
70  fgInstance = nullptr;
71  if (fMCManager) {
72  delete fMCManager;
73  }
74 }
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 ///
78 /// Static access method
79 ///
80 
82 {
83  return fgInstance;
84 }
85 
86 ////////////////////////////////////////////////////////////////////////////////
87 ///
88 /// For backwards compatibility provide a static GetMC method
89 ///
90 
92 {
93  fMCManager = new TMCManager();
94  fMCManager->Register(this);
97 }
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 ///
101 /// /// Register the an engine.
102 ///
103 
105 {
106  // If there is already a transport engine, fail since only one is allowed.
107  if (fMC && !fMCManager) {
108  Fatal("Register", "Attempt to register a second TVirtualMC which "
109  "is not allowed");
110  }
111  fMC = mc;
112  if (fMCManager) {
113  fMCManager->Register(mc);
114  }
115 }
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 ///
119 /// Return the current transport engine in use
120 ///
121 
123 {
124  return fMC;
125 }
void ConnectEnginePointer(TVirtualMC **mc)
Connect a pointer which is updated whenever the engine is changed.
Definition: TMCManager.cxx:199
Singleton manager class for handling and steering a run with multiple TVirtualMC engines sharing even...
Definition: TMCManager.h:36
static TMCThreadLocal TVirtualMCApplication * fgInstance
Singleton instance.
void Register(TVirtualMC *engine)
A TVirtualMC will register itself via this method during construction if a TMCManager was instanciate...
Definition: TMCManager.cxx:86
void RequestMCManager()
Request a TMCManager which is required if multiple engines should be run.
TVirtualMC * GetMC() const
Return the transport engine registered to this application.
bool Bool_t
Definition: RtypesCore.h:59
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual ~TVirtualMCApplication()
Destructor.
static Bool_t fLockMultiThreading
Forbid multithreading mode if multi run via global static flag.
Interface to a user Monte Carlo application.
const Bool_t kFALSE
Definition: RtypesCore.h:88
#define TMCThreadLocal
Definition: TMCtls.h:80
Abstract Monte Carlo interface.
Definition: TVirtualMC.h:42
TMCManager * fMCManager
Pointer to requested TMCManager which will only be instantiated by a call to RequestMCManager() ...
TVirtualMC * fMC
The current transport engine in use.
static TVirtualMCApplication * Instance()
Static access method.
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:908
void Register(TVirtualMC *mc)
Register the an engine.
const Bool_t kTRUE
Definition: RtypesCore.h:87
TVirtualMCApplication()
Default constructor.
char name[80]
Definition: TGX11.cxx:109