]> git.uio.no Git - u/mrichter/AliRoot.git/blame - AliGeant4/AliRunAction.cxx
cuts on Q out, side, long added
[u/mrichter/AliRoot.git] / AliGeant4 / AliRunAction.cxx
CommitLineData
676fb573 1// $Id$
2// Category: run
3//
48d2d644 4// Author: I. Hrivnacova
5//
6// Class AliRunAction
7// ------------------
676fb573 8// See the class description in the header file.
9
10#include <G4Timer.hh>
11 // in order to avoid the odd dependency for the
12 // times system function this include must be the first
13
14#include "AliRunAction.h"
fdfcba4c 15#include "AliSDConstruction.h"
676fb573 16#include "AliGlobals.h"
17#include "AliRun.h"
fbbe0dd8 18#include "AliHeader.h"
676fb573 19#include "AliLego.h"
20
fdfcba4c 21#include "TG4SDManager.h"
22#include "TG4VSDConstruction.h"
676fb573 23
24#include <G4Run.hh>
4a14e919 25#include <G4VVisManager.hh>
676fb573 26#include <G4UImanager.hh>
27
fdfcba4c 28//_____________________________________________________________________________
676fb573 29AliRunAction::AliRunAction()
f5dd23f1 30 : AliVerbose("runAction"),
31 fRunID(-1)
676fb573 32{
33//
676fb573 34 fTimer = new G4Timer;
35}
36
fdfcba4c 37//_____________________________________________________________________________
48d2d644 38AliRunAction::AliRunAction(const AliRunAction& right)
f5dd23f1 39 : AliVerbose("runAction") {
676fb573 40//
41 AliGlobals::Exception("AliRunAction is protected from copying.");
42}
43
fdfcba4c 44//_____________________________________________________________________________
676fb573 45AliRunAction::~AliRunAction() {
46//
676fb573 47 delete fTimer;
48}
49
50// operators
51
fdfcba4c 52//_____________________________________________________________________________
676fb573 53AliRunAction& AliRunAction::operator=(const AliRunAction &right)
54{
55 // check assignement to self
56 if (this == &right) return *this;
57
58 AliGlobals::Exception("AliRunAction is protected from assigning.");
59
60 return *this;
61}
62
fdfcba4c 63// private methods
64
65//_____________________________________________________________________________
66AliSDConstruction* AliRunAction::GetSDConstruction() const
67{
68// Gets sensitive detectors construction and checks type.
69// ---
70
71 TG4VSDConstruction* tg4SDConstruction
72 = TG4SDManager::Instance()->GetSDConstruction();
73
74 AliSDConstruction* aliSDConstruction
75 = dynamic_cast<AliSDConstruction*>(tg4SDConstruction);
76
77 if (!aliSDConstruction) {
78 G4String text = "AliRunAction::GetSDConstruction:\n";
79 text = text + " Unknown type.";
80 AliGlobals::Exception(text);
81 return 0;
82 }
83
84 return aliSDConstruction;
85}
86
676fb573 87// public methods
88
fdfcba4c 89//_____________________________________________________________________________
676fb573 90void AliRunAction::BeginOfRunAction(const G4Run* run)
91{
92// Called by G4 kernel at the beginning of run.
93// ---
94
95 fRunID++;
96
97 // aliroot
98 // store runID in the event header
99 gAlice->GetHeader()->SetRun(fRunID);
100
676fb573 101 // create lego sensitive detectors
102 // if lego is instantiated
103 AliLego* lego = gAlice->Lego();
104 if (lego) {
fdfcba4c 105 GetSDConstruction()->SetLego(lego);
6289baa7 106 G4UImanager::GetUIpointer()->ApplyCommand("/aliVerbose/eventAction 0");
676fb573 107 G4UImanager::GetUIpointer()->ApplyCommand("/aliGenerator/set AliGenerator");
108 }
109
4a14e919 110 // notify graphics
111 if (G4VVisManager::GetConcreteInstance()) {
112 G4UImanager::GetUIpointer()->ApplyCommand("/vis/scene/notifyHandlers");
113 }
114
f5dd23f1 115 if (VerboseLevel() > 0) {
116 G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
117 }
118
676fb573 119 fTimer->Start();
120}
121
fdfcba4c 122//_____________________________________________________________________________
676fb573 123void AliRunAction::EndOfRunAction(const G4Run* run)
124{
125// Called by G4 kernel at the end of run.
126// ---
127
128 fTimer->Stop();
129
130 // delete lego sensitive detectors
131 // if lego is instantiated
132 AliLego* lego = gAlice->Lego();
133 if (lego) {
fdfcba4c 134 GetSDConstruction()->UnsetLego();
6289baa7 135 G4UImanager::GetUIpointer()->ApplyCommand("/aliVerbose/eventAction 0");
676fb573 136 }
137
4a14e919 138 // update graphics
139 if (G4VVisManager::GetConcreteInstance()) {
140 G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/update");
141 }
142
f5dd23f1 143 if (VerboseLevel() > 0) {
144 G4cout << "Time of this run: " << *fTimer << G4endl;
145 G4cout << "Number of events processed: " << run->GetNumberOfEvent() << G4endl;
146 }
676fb573 147}