]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TGeant4/TG4RunManager.cxx
removed unnecessary includes
[u/mrichter/AliRoot.git] / TGeant4 / TG4RunManager.cxx
CommitLineData
2817d3e2 1// $Id$
2// Category: run
3//
4// See the class description in the header file.
5
6#include "TG4RunManager.h"
7#include "TG4RunMessenger.h"
8#include "TG4VRunConfiguration.h"
2817d3e2 9#include "TG4Globals.h"
10#include "TG4GeometryManager.h"
11#include "TG4PhysicsManager.h"
12//#include "TG4StepManager.h"
13
14#include <G4RunManager.hh>
2817d3e2 15#include <G4UIsession.hh>
16#include <G4UImanager.hh>
17#include <G4UIterminal.hh>
18#include <G4UIXm.hh>
19#ifdef G4UI_USE_WO
20#include <G4UIWo.hh>
21#endif
22#ifdef G4UI_USE_GAG
23#include <G4UIGAG.hh>
24#endif
2817d3e2 25
26#include <TRint.h>
27#include <TROOT.h>
28#include <TCint.h>
29
30TG4RunManager* TG4RunManager::fgInstance = 0;
31
32TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration,
33 int argc, char** argv)
34 : fRunConfiguration(runConfiguration),
35 fGeantUISession(0),
36 fRootUISession(0),
37 fRootUIOwner(false),
38 fARGC(argc),
39 fARGV(argv)
40
41{
42//
43 if (fgInstance) {
44 TG4Globals::Exception(
45 "TG4RunManager: attempt to create two instances of singleton.");
46 };
47
48 if (!fRunConfiguration) {
49 TG4Globals::Exception(
50 "TG4RunManager: attempt to create instance without runConfiguration.");
51 };
52
53 fgInstance = this;
54
55 // create and configure geant4 run manager
56 fRunManager = new G4RunManager();
57 fRunConfiguration->ConfigureRunManager(fRunManager);
58 // add verbose level
3c7cd15a 59 //G4cout << "G4RunManager has been created." << G4endl;
2817d3e2 60
61 // create geant4 UI
62 CreateGeantUI();
63 // must be created before TG4VisManager::Initialize()
64 // (that is invoked in TGeant4 constructor)
65
66 // create root UI
67 CreateRootUI();
68
69 // messenger
70 fMessenger = new TG4RunMessenger(this);
71}
72
73TG4RunManager::TG4RunManager(TG4VRunConfiguration* runConfiguration)
74 : fRunConfiguration(runConfiguration),
75 fGeantUISession(0),
76 fRootUISession(0),
77 fRootUIOwner(false),
78 fARGC(0),
79 fARGV(0)
80
81{
82//
83 if (fgInstance) {
84 TG4Globals::Exception(
85 "TG4RunManager: attempt to create two instances of singleton.");
86 };
87
88 if (!fRunConfiguration) {
89 TG4Globals::Exception(
90 "TG4RunManager: attempt to create instance without runConfiguration.");
91 };
92
93 fgInstance = this;
94
95 // set primary UI
96 fRootUISession = gROOT->GetApplication();
97 if (fRootUISession) {
98 fARGC = fRootUISession->Argc();
99 fARGV = fRootUISession->Argv();
100 }
101
102 // create and configure geant4 run manager
103 fRunManager = new G4RunManager();
104 fRunConfiguration->ConfigureRunManager(fRunManager);
105 // add verbose level
3c7cd15a 106 //G4cout << "G4RunManager has been created." << G4endl;
2817d3e2 107
108 // create geant4 UI
109 CreateGeantUI();
110 // must be created before TG4VisManager::Initialize()
111 // (that is invoked in TGeant4 constructor)
112
113 // create root UI
114 CreateRootUI();
115
116 // messenger
117 fMessenger = new TG4RunMessenger(this);
118}
119
120TG4RunManager::TG4RunManager() {
121//
122}
123
124TG4RunManager::TG4RunManager(const TG4RunManager& right) {
125//
126 TG4Globals::Exception(
127 "Attempt to copy TG4RunManager singleton.");
128}
129
130TG4RunManager::~TG4RunManager() {
131//
132 delete fRunConfiguration;
133 delete fRunManager;
134 delete fGeantUISession;
135 if (fRootUIOwner) delete fRootUISession;
136 delete fMessenger;
137}
138
139// operators
140
141TG4RunManager& TG4RunManager::operator=(const TG4RunManager& right)
142{
143 // check assignement to self
144 if (this == &right) return *this;
145
146 TG4Globals::Exception(
147 "Attempt to assign TG4RunManager singleton.");
148
149 return *this;
150}
151
152// private methods
153
154void TG4RunManager::CreateGeantUI()
155{
156// Creates interactive Geant4.
157// ---
158
159 if (!fGeantUISession)
160 {
161 // create geant4 UI
162 G4UImanager* pUI = G4UImanager::GetUIpointer();
163 if (fARGC == 1) {
164#ifdef G4UI_USE_GAG
165 fGeantUISession = new G4UIGAG();
166#else
167 fGeantUISession = new G4UIterminal();
168#endif
169 }
170 else if (strcmp (fARGV[1], "dumb") == 0) {
171 fGeantUISession = new G4UIterminal();
172 }
173#ifdef G4UI_USE_WO
174 else if (strcmp (fARGV[1], "Wo") == 0) {
175 fGeantUISession = new G4UIWo(fARGC, fARGV);
176 }
177#endif
178#ifdef G4UI_USE_XM
179 else if (strcmp (fARGV[1], "Xm") == 0) {
180 fGeantUISession = new G4UIXm(fARGC, fARGV);
181 }
182#endif
183#ifdef G4UI_USE_XAW
184 else if (strcmp (fARGV[1], "Xaw") == 0) {
185 fGeantUISession = new G4UIXaw(fARGC, fARGV);
186 }
187#endif
188#ifdef G4UI_USE_GAG
189 else if (strcmp (fARGV[1], "GAG") == 0) {
190 fGeantUISession = new G4UIGAG ();
191 }
192#endif
193 if (fGeantUISession) {
194 pUI->SetSession(fGeantUISession);
195 }
196 }
197}
198
199void TG4RunManager::CreateRootUI()
200{
201// Creates interactive Root.
202// ---
203
204 if (!fRootUISession)
205 {
206 // create session if it does not exist
207 fRootUISession = new TRint("aliroot", 0, 0, 0, 0);
208
209 // set ownership of Root UI
210 fRootUIOwner = true;
211 }
212}
213
214// public methods
215
216void TG4RunManager::Initialize()
217{
218// Initializes G4.
219// ---
220
221 // initialize Geant4
222 fRunManager->Initialize();
223
224 // activate/inactivate physics processes
225 // (this operation is not allowed in "Init" phase)
226 TG4PhysicsManager* physicsManager = TG4PhysicsManager::Instance();
227 physicsManager->SetProcessActivation();
228}
229
230void TG4RunManager::ProcessEvent()
231{
232// Not yet implemented.
233// ---
234
235 TG4Globals::Warning("TG4RunManager::ProcessEvent(): is not yet implemented.");
236}
237
238void TG4RunManager::ProcessRun(G4int nofEvents)
239{
240// Processes Geant4 run.
241// ---
242
243 fRunManager->BeamOn(nofEvents);
244}
245
246void TG4RunManager::StartGeantUI()
247{
248// Starts interactive/batch Geant4.
249// ---
250
251 if (!fGeantUISession) CreateGeantUI();
252 if (fGeantUISession) {
253 // interactive session
3c7cd15a 254 G4cout << "Welcome back in Geant4" << G4endl;
2817d3e2 255 fGeantUISession->SessionStart();
3c7cd15a 256 G4cout << "Welcome back in Root" << G4endl;
2817d3e2 257 }
258 else {
259 // execute Geant4 macro if file is specified as an argument
260 G4String fileName = fARGV[1];
261 ProcessGeantMacro(fileName);
262 }
263}
264
265void TG4RunManager::StartRootUI()
266{
267// Starts interactive Root.
268// ---
269
270 if (!fRootUISession) CreateRootUI();
271 if (fRootUISession) {
3c7cd15a 272 G4cout << "Welcome back in Root" << G4endl;
2817d3e2 273 fRootUISession->Run(kTRUE);
3c7cd15a 274 G4cout << "Welcome back in Geant4" << G4endl;
2817d3e2 275 }
276}
277
278void TG4RunManager::ProcessGeantMacro(G4String macroName)
279{
280// Processes Geant4 macro.
281// ---
282
283 G4String command = "/control/execute " + macroName;
284 ProcessGeantCommand(command);
285}
286
287void TG4RunManager::ProcessRootMacro(G4String macroName)
288{
289// Processes Root macro.
290// ---
291
292 // load macro file
293 G4String macroFile = macroName;
294 macroFile.append(".C");
295 gROOT->LoadMacro(macroFile);
296
297 // execute macro function
298 G4String macroFunction = macroName;
299 macroFunction.append("()");
300 gInterpreter->ProcessLine(macroFunction);
301}
302
303void TG4RunManager::ProcessGeantCommand(G4String command)
304{
305// Processes Geant4 command.
306// ---
307
308 G4UImanager* pUI = G4UImanager::GetUIpointer();
309 pUI->ApplyCommand(command);
310}
311
312void TG4RunManager::ProcessRootCommand(G4String command)
313{
314// Processes Root command.
315// ---
316
317 gInterpreter->ProcessLine(command);
318}
319
320void TG4RunManager::UseG3Defaults()
321{
322// Controls G3 defaults usage.
323// ---
324
325 TG4GeometryManager::Instance()->UseG3TrackingMediaLimits();
326 TG4PhysicsManager::Instance()->SetG3DefaultCuts();
327 TG4PhysicsManager::Instance()->SetG3DefaultProcesses();
328}
329
330Int_t TG4RunManager::CurrentEvent() const
331{
332// Returns the number of the current event.
333// ---
334
335 G4int eventID = fRunManager->GetCurrentEvent()->GetEventID();
336 return eventID;
337}